Add is_list_constructible

This commit is contained in:
Peter Dimov
2017-07-15 23:03:38 +03:00
parent 64421a443b
commit ced4870cb0
6 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,23 @@
[/
Copyright 2017 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
]
[section:is_list_constructible is_list_constructible]
template <class T, class... Args>
struct is_list_constructible : public __tof {};
__inherit If `T` can be constructed from `Args` using list initialization
(`T{declval<Args>()...}`), then inherits from __true_type, otherwise inherits from
__false_type. `T` must be a complete type.
__compat This trait requires C++11.
__header ` #include <boost/type_traits/is_list_constructible.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]

View File

@ -72,6 +72,7 @@
[def __is_copy_constructible [link boost_typetraits.reference.is_copy_constructible is_copy_constructible]]
[def __is_copy_assignable [link boost_typetraits.reference.is_copy_assignable is_copy_assignable]]
[def __is_constructible [link boost_typetraits.reference.is_constructible is_constructible]]
[def __is_list_constructible [link boost_typetraits.reference.is_list_constructible is_list_constructible]]
[def __is_default_constructible [link boost_typetraits.reference.is_default_constructible is_default_constructible]]
[def __is_destructible [link boost_typetraits.reference.is_destructible is_destructible]]
[def __is_volatile [link boost_typetraits.reference.is_volatile is_volatile]]
@ -294,6 +295,7 @@ See __has_trivial_constructor.
[include is_function.qbk]
[include is_fundamental.qbk]
[include is_integral.qbk]
[include is_list_constructible.qbk]
[include is_lvalue_reference.qbk]
[include is_member_function_pointer.qbk]
[include is_member_object_pointer.qbk]

View File

@ -168,6 +168,9 @@ The following templates describe the general properties of a type.
template <class T>
struct __is_default_constructible;
template <class T, class... Args>
struct __is_list_constructible;
template <class T>
struct __is_destructible;

View File

@ -107,6 +107,7 @@
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/is_fundamental.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_list_constructible.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/type_traits/is_member_object_pointer.hpp>

View File

@ -0,0 +1,41 @@
#ifndef BOOST_TYPE_TRAITS_IS_LIST_CONSTRUCTIBLE_HPP_INCLUDED
#define BOOST_TYPE_TRAITS_IS_LIST_CONSTRUCTIBLE_HPP_INCLUDED
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/declval.hpp>
namespace boost
{
#if defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) || defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
template<class T, class = void, class = void, class = void, class = void, class = void, class = void> struct is_list_constructible: false_type
{
};
#else
namespace type_traits_detail
{
template<class T, class... A, class = decltype( T{declval<A>()...} )> true_type is_list_constructible_impl( int );
template<class T, class... A> false_type is_list_constructible_impl( ... );
} // namespace type_traits_detail
template<class T, class... A> struct is_list_constructible: decltype( type_traits_detail::is_list_constructible_impl<T, A...>(0) )
{
};
#endif
} // namespace boost
#endif // #ifndef BOOST_TYPE_TRAITS_IS_LIST_CONSTRUCTIBLE_HPP_INCLUDED

View File

@ -0,0 +1,95 @@
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#if defined( __GNUC__ ) && (__GNUC__ >= 7)
#pragma GCC diagnostic ignored "-Wnarrowing"
#endif
#ifdef TEST_STD
# include <type_traits>
#else
# include <boost/type_traits/is_list_constructible.hpp>
#endif
#include "test.hpp"
#include "check_integral_constant.hpp"
#if defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_DECLTYPE) \
|| defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) || defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
int main() {}
#else
#include <vector>
struct X
{
int a;
int b;
};
struct Y
{
Y( int = 0, int = 0 );
};
struct Z
{
explicit Z( int = 0, int = 0 );
};
struct V
{
V( int&, int& );
};
TT_TEST_BEGIN(is_list_constructible)
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, char>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int const, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int const, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, int>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int const, int const>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, float>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int, int, int>::value), false);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int&, int&>::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int const&, int const&>::value), false);
TT_TEST_END
#endif