diff --git a/doc/detected.qbk b/doc/detected.qbk index 59b1032..2a0e149 100644 --- a/doc/detected.qbk +++ b/doc/detected.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/detected_or.qbk b/doc/detected_or.qbk index e036fd0..72a994e 100644 --- a/doc/detected_or.qbk +++ b/doc/detected_or.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/enable_if.qbk b/doc/enable_if.qbk new file mode 100644 index 0000000..adf96c6 --- /dev/null +++ b/doc/enable_if.qbk @@ -0,0 +1,48 @@ +[/ +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +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:enable_if enable_if_] + + template + struct enable_if_; + + template + using enable_if_t = typename enable_if_::type; + +__type If `B` is true, then the member `type` is defined to be `T`. Otherwise +there is no member `type`. + +__header `#include ` + +[note The trait has the name `enable_if_` (with a trailing underscore) but +behaves like `std::enable_if` or `boost::enable_if_c`. The existing trait +with the name `boost::enable_if` has a different interface.] + +__examples + +The following function can be used to destroy each element of an array and +specially handle arrays of trivially destructible types. + + template + typename boost::enable_if_::value>::type + destroy(T* ptr, std::size_t size) + { + while (size > 0) { + ptr[--size].~T(); + } + } + + template + typename boost::enable_if_::value>::type + destroy(T*, std::size_t) { } + +[all_compilers] The type alias `enable_if_t` is only available if the compiler +supports template aliases. + +[endsect] diff --git a/doc/is_detected.qbk b/doc/is_detected.qbk index b788af5..2add44a 100644 --- a/doc/is_detected.qbk +++ b/doc/is_detected.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/is_detected_convertible.qbk b/doc/is_detected_convertible.qbk index 0408528..ac6fbb8 100644 --- a/doc/is_detected_convertible.qbk +++ b/doc/is_detected_convertible.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/is_detected_exact.qbk b/doc/is_detected_exact.qbk index 705673a..5d5c922 100644 --- a/doc/is_detected_exact.qbk +++ b/doc/is_detected_exact.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/make_void.qbk b/doc/make_void.qbk index 3ae0e3d..8b8d506 100644 --- a/doc/make_void.qbk +++ b/doc/make_void.qbk @@ -1,6 +1,6 @@ [/ Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/nonesuch.qbk b/doc/nonesuch.qbk index 6809604..be438b1 100644 --- a/doc/nonesuch.qbk +++ b/doc/nonesuch.qbk @@ -1,6 +1,6 @@ [/ Copyright 2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index ebc545b..abc2da2 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -309,6 +309,7 @@ that is the result of the transformation. [include declval.qbk] [include detected.qbk] [include detected_or.qbk] +[include enable_if.qbk] [include extent.qbk] [include floating_point_promotion.qbk] [include function_traits.qbk] diff --git a/include/boost/type_traits.hpp b/include/boost/type_traits.hpp index 9f024b1..a767e41 100644 --- a/include/boost/type_traits.hpp +++ b/include/boost/type_traits.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/type_traits/detail/detector.hpp b/include/boost/type_traits/detail/detector.hpp index 007a4dc..f13a1f9 100644 --- a/include/boost/type_traits/detail/detector.hpp +++ b/include/boost/type_traits/detail/detector.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/detail/is_likely_lambda.hpp b/include/boost/type_traits/detail/is_likely_lambda.hpp index 6da8aca..39aa528 100644 --- a/include/boost/type_traits/detail/is_likely_lambda.hpp +++ b/include/boost/type_traits/detail/is_likely_lambda.hpp @@ -30,7 +30,7 @@ struct is_likely_stateless_lambda : public false_type {}; #elif !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !BOOST_WORKAROUND(BOOST_MSVC, < 1900) #include -#include +#include namespace boost{ @@ -70,7 +70,7 @@ struct is_likely_stateless_lambda : false_type{}; template struct is_likely_stateless_lambda< T, - typename boost::enable_if_c::value>::type> : + typename boost::enable_if_::value>::type> : boost::is_convertible::type >{}; diff --git a/include/boost/type_traits/detected.hpp b/include/boost/type_traits/detected.hpp index f9a4d85..96a38a2 100644 --- a/include/boost/type_traits/detected.hpp +++ b/include/boost/type_traits/detected.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/detected_or.hpp b/include/boost/type_traits/detected_or.hpp index 676ac06..e79e02a 100644 --- a/include/boost/type_traits/detected_or.hpp +++ b/include/boost/type_traits/detected_or.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/enable_if.hpp b/include/boost/type_traits/enable_if.hpp new file mode 100644 index 0000000..3cdc281 --- /dev/null +++ b/include/boost/type_traits/enable_if.hpp @@ -0,0 +1,37 @@ +/* +Copyright 2003 The Trustees of Indiana University + +Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) + Jeremiah Willcock (jewillco at osl.iu.edu) + Andrew Lumsdaine (lums at osl.iu.edu) + +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +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) +*/ +#ifndef BOOST_TT_ENABLE_IF_HPP_INCLUDED +#define BOOST_TT_ENABLE_IF_HPP_INCLUDED + +#include + +namespace boost { + +template +struct enable_if_ { + typedef T type; +}; + +template +struct enable_if_ { }; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +using enable_if_t = typename enable_if_::type; +#endif + +} /* boost */ + +#endif diff --git a/include/boost/type_traits/is_copy_assignable.hpp b/include/boost/type_traits/is_copy_assignable.hpp index 76afdda..ed04927 100644 --- a/include/boost/type_traits/is_copy_assignable.hpp +++ b/include/boost/type_traits/is_copy_assignable.hpp @@ -11,8 +11,7 @@ #include #include -#include -#include +#include #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_NO_CXX11_DECLTYPE) \ && !defined(BOOST_INTEL_CXX_VERSION) && \ @@ -112,7 +111,7 @@ struct is_copy_assignable_impl { typedef BOOST_DEDUCED_TYPENAME boost::remove_reference::type unreferenced_t; BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_assignable_impl2< - boost::is_base_and_derived::value + boost::is_noncopyable::value || boost::is_const::value || boost::is_array::value ,T >::value @@ -120,7 +119,7 @@ struct is_copy_assignable_impl { #else BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_assignable_impl2< - boost::is_base_and_derived::value,T + boost::is_noncopyable::value,T >::value )); #endif diff --git a/include/boost/type_traits/is_copy_constructible.hpp b/include/boost/type_traits/is_copy_constructible.hpp index c688264..ef97e18 100644 --- a/include/boost/type_traits/is_copy_constructible.hpp +++ b/include/boost/type_traits/is_copy_constructible.hpp @@ -37,8 +37,7 @@ template <> struct is_copy_constructible : public false_type{}; // an incorrect value, which just defers the issue into the users code) as well. We can at least fix // boost::non_copyable as a base class as a special case: // -#include -#include +#include namespace boost { @@ -50,7 +49,7 @@ namespace boost { } - template struct is_copy_constructible : public detail::is_copy_constructible_imp::value>{}; + template struct is_copy_constructible : public detail::is_copy_constructible_imp::value>{}; template <> struct is_copy_constructible : public false_type{}; template <> struct is_copy_constructible : public false_type{}; @@ -64,13 +63,12 @@ namespace boost { #else #include -#include +#include #include #include #include #include #include -#include #ifdef BOOST_MSVC #pragma warning(push) @@ -160,7 +158,7 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_constructible_impl2< - boost::is_base_and_derived::value, + boost::is_noncopyable::value, T >::value )); diff --git a/include/boost/type_traits/is_detected.hpp b/include/boost/type_traits/is_detected.hpp index 8bff9d9..25dfa84 100644 --- a/include/boost/type_traits/is_detected.hpp +++ b/include/boost/type_traits/is_detected.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/is_detected_convertible.hpp b/include/boost/type_traits/is_detected_convertible.hpp index 8a6d82f..538ba25 100644 --- a/include/boost/type_traits/is_detected_convertible.hpp +++ b/include/boost/type_traits/is_detected_convertible.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/is_detected_exact.hpp b/include/boost/type_traits/is_detected_exact.hpp index 1a9b045..34f714c 100644 --- a/include/boost/type_traits/is_detected_exact.hpp +++ b/include/boost/type_traits/is_detected_exact.hpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/is_noncopyable.hpp b/include/boost/type_traits/is_noncopyable.hpp new file mode 100644 index 0000000..787103e --- /dev/null +++ b/include/boost/type_traits/is_noncopyable.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED +#define BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED + +// +// Copyright 2018 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 +// +// is_noncopyable returns whether T is derived from boost::noncopyable +// + +#include + +namespace boost +{ + +#ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED +#define BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED + +// boost::noncopyable derives from noncopyable_::base_token to enable us +// to recognize it. The definition is macro-guarded so that we can replicate +// it here without including boost/core/noncopyable.hpp, which is in Core. + +namespace noncopyable_ +{ + struct base_token {}; +} + +#endif // #ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED + +template struct is_noncopyable: is_base_and_derived +{ +}; + +} // namespace boost + +#endif // #ifndef BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED diff --git a/include/boost/type_traits/is_nothrow_move_assignable.hpp b/include/boost/type_traits/is_nothrow_move_assignable.hpp index 5f63cb7..c6194de 100644 --- a/include/boost/type_traits/is_nothrow_move_assignable.hpp +++ b/include/boost/type_traits/is_nothrow_move_assignable.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -48,7 +48,7 @@ struct false_or_cpp11_noexcept_move_assignable: public ::boost::false_type {}; template struct false_or_cpp11_noexcept_move_assignable < T, - typename ::boost::enable_if_c() = ::boost::declval())>::type + typename ::boost::enable_if_() = ::boost::declval())>::type > : public ::boost::integral_constant() = ::boost::declval())> {}; diff --git a/include/boost/type_traits/is_nothrow_move_constructible.hpp b/include/boost/type_traits/is_nothrow_move_constructible.hpp index 30b6a16..60c2994 100644 --- a/include/boost/type_traits/is_nothrow_move_constructible.hpp +++ b/include/boost/type_traits/is_nothrow_move_constructible.hpp @@ -35,7 +35,7 @@ template struct is_nothrow_move_constructible : publ #elif !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700) #include -#include +#include namespace boost{ namespace detail{ @@ -45,7 +45,7 @@ struct false_or_cpp11_noexcept_move_constructible: public ::boost::false_type {} template struct false_or_cpp11_noexcept_move_constructible < T, - typename ::boost::enable_if_c()))>::type + typename ::boost::enable_if_()))>::type > : public ::boost::integral_constant()))> {}; diff --git a/include/boost/type_traits/make_void.hpp b/include/boost/type_traits/make_void.hpp index f48823b..b8a72ef 100644 --- a/include/boost/type_traits/make_void.hpp +++ b/include/boost/type_traits/make_void.hpp @@ -1,6 +1,6 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/include/boost/type_traits/nonesuch.hpp b/include/boost/type_traits/nonesuch.hpp index 85466b4..7ba98c4 100644 --- a/include/boost/type_traits/nonesuch.hpp +++ b/include/boost/type_traits/nonesuch.hpp @@ -1,6 +1,6 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/detected_or_test.cpp b/test/detected_or_test.cpp index d737b40..e4d1d4d 100644 --- a/test/detected_or_test.cpp +++ b/test/detected_or_test.cpp @@ -1,6 +1,6 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/detected_test.cpp b/test/detected_test.cpp index 6eee462..4ffcd3d 100644 --- a/test/detected_test.cpp +++ b/test/detected_test.cpp @@ -1,6 +1,6 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/enable_if_test.cpp b/test/enable_if_test.cpp new file mode 100644 index 0000000..f3a30a0 --- /dev/null +++ b/test/enable_if_test.cpp @@ -0,0 +1,92 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +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 "test.hpp" + +template +struct Constant { + enum { + value = B + }; +}; + +template +struct Check + : Constant { }; + +template<> +struct Check + : Constant { }; + +class Construct { +public: + template + Construct(T, typename boost::enable_if_::value>::type* = 0) + : value_(true) { } + template + Construct(T, typename boost::enable_if_::value>::type* = 0) + : value_(false) { } + bool value() const { + return value_; + } +private: + bool value_; +}; + +template +struct Specialize; + +template +struct Specialize::value>::type> + : Constant { }; + +template +struct Specialize::value>::type> + : Constant { }; + +template +typename boost::enable_if_::value, bool>::type Returns(T) +{ + return true; +} + +template +typename boost::enable_if_::value, bool>::type Returns(T) +{ + return false; +} + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +boost::enable_if_t::value, bool> Alias(T) +{ + return true; +} + +template +boost::enable_if_t::value, bool> Alias(T) +{ + return false; +} +#endif + +TT_TEST_BEGIN(enable_if) + +BOOST_CHECK(!Construct(1).value()); +BOOST_CHECK(Construct(1L).value()); +BOOST_CHECK(!Specialize::value); +BOOST_CHECK(Specialize::value); +BOOST_CHECK(!Returns(1)); +BOOST_CHECK(Returns(1L)); +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +BOOST_CHECK(!Alias(1)); +BOOST_CHECK(Alias(1L)); +#endif + +TT_TEST_END diff --git a/test/is_convertible_test.cpp b/test/is_convertible_test.cpp index 8b33c03..92321db 100644 --- a/test/is_convertible_test.cpp +++ b/test/is_convertible_test.cpp @@ -11,7 +11,7 @@ #endif #include "test.hpp" #include "check_integral_constant.hpp" -#include +#include template @@ -30,7 +30,7 @@ template struct test_bug_4530 { template - test_bug_4530(A&&, typename boost::enable_if< ::tt::is_convertible >::type* =0); + test_bug_4530(A&&, typename boost::enable_if_< ::tt::is_convertible::value >::type* =0); }; struct A4530 diff --git a/test/is_detected_convertible.cpp b/test/is_detected_convertible.cpp index c98e273..2a5ef2c 100644 --- a/test/is_detected_convertible.cpp +++ b/test/is_detected_convertible.cpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/is_detected_exact_test.cpp b/test/is_detected_exact_test.cpp index 4b1a071..87a9ec1 100644 --- a/test/is_detected_exact_test.cpp +++ b/test/is_detected_exact_test.cpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/is_detected_test.cpp b/test/is_detected_test.cpp index a58987b..5a75b9e 100644 --- a/test/is_detected_test.cpp +++ b/test/is_detected_test.cpp @@ -1,6 +1,6 @@ /* Copyright 2017-2018 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/test/is_noncopyable_test.cpp b/test/is_noncopyable_test.cpp new file mode 100644 index 0000000..57d41d5 --- /dev/null +++ b/test/is_noncopyable_test.cpp @@ -0,0 +1,46 @@ + +// (C) Copyright John Maddock 2000. +// (C) Copyright Peter Dimov 2018. +// Use, modification and distribution are subject to 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) + +#ifdef TEST_STD +# include +#else +# include +#endif +#include +#include "test.hpp" +#include "check_integral_constant.hpp" + +struct X +{ +}; + +class Y: private boost::noncopyable +{ +}; + +class Z: private Y +{ +}; + +TT_TEST_BEGIN(is_noncopyable) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); + +TT_TEST_END diff --git a/test/make_void_test.cpp b/test/make_void_test.cpp index f63b55e..41c4899 100644 --- a/test/make_void_test.cpp +++ b/test/make_void_test.cpp @@ -1,6 +1,6 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt