diff --git a/doc/is_list_constructible.qbk b/doc/is_list_constructible.qbk new file mode 100644 index 0000000..733d2e8 --- /dev/null +++ b/doc/is_list_constructible.qbk @@ -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 + struct is_list_constructible : public __tof {}; + +__inherit If `T` can be constructed from `Args` using list initialization +(`T{declval()...}`), then inherits from __true_type, otherwise inherits from +__false_type. `T` must be a complete type. + +__compat This trait requires C++11. + +__header ` #include ` or ` #include ` + +[endsect] diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index 1a1fa5b..0c917e1 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -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] diff --git a/doc/value_traits.qbk b/doc/value_traits.qbk index 5f667aa..f8ff399 100644 --- a/doc/value_traits.qbk +++ b/doc/value_traits.qbk @@ -168,6 +168,9 @@ The following templates describe the general properties of a type. template struct __is_default_constructible; + template + struct __is_list_constructible; + template struct __is_destructible; diff --git a/include/boost/type_traits.hpp b/include/boost/type_traits.hpp index dbc8c95..e5810b4 100644 --- a/include/boost/type_traits.hpp +++ b/include/boost/type_traits.hpp @@ -107,6 +107,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/type_traits/is_list_constructible.hpp b/include/boost/type_traits/is_list_constructible.hpp new file mode 100644 index 0000000..518a75b --- /dev/null +++ b/include/boost/type_traits/is_list_constructible.hpp @@ -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 +#include +#include + +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 struct is_list_constructible: false_type +{ +}; + +#else + +namespace type_traits_detail +{ + +template()...} )> true_type is_list_constructible_impl( int ); +template false_type is_list_constructible_impl( ... ); + +} // namespace type_traits_detail + +template struct is_list_constructible: decltype( type_traits_detail::is_list_constructible_impl(0) ) +{ +}; + +#endif + +} // namespace boost + +#endif // #ifndef BOOST_TYPE_TRAITS_IS_LIST_CONSTRUCTIBLE_HPP_INCLUDED diff --git a/test/is_list_constructible_test.cpp b/test/is_list_constructible_test.cpp new file mode 100644 index 0000000..d659196 --- /dev/null +++ b/test/is_list_constructible_test.cpp @@ -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 +#else +# include +#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 + +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::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); + +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); + +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); + +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); + +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), true); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible::value), false); + +TT_TEST_END + +#endif