forked from boostorg/type_traits
Implement detection idiom toolkit
This commit is contained in:
1 parent
5d5c651ea6
commit
35c105501b
21 files changed
+662
-2
No files matched your search
+2
-2
@@ -18,8 +18,8 @@ current maintainer of the library.
|
||||
This version of type traits library is based on contributions by
|
||||
Adobe Systems Inc, David Abrahams, Steve Cleary,
|
||||
Beman Dawes, Aleksey Gurtovoy, Howard Hinnant, Jesse Jones, Mat Marcus,
|
||||
Itay Maman, John Maddock, Thorsten Ottosen, Robert Ramey, Jeremy Siek
|
||||
and Antony Polukhin.
|
||||
Itay Maman, John Maddock, Thorsten Ottosen, Robert Ramey, Jeremy Siek,
|
||||
Antony Polukhin and Glen Fernandes.
|
||||
|
||||
Mat Marcus and Jesse Jones invented, and
|
||||
[@http://opensource.adobe.com/project4/project.shtml published a paper describing],
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:detected detected]
|
||||
|
||||
template<template<class...> class Op, class... Args>
|
||||
using detected_t = __below;
|
||||
|
||||
__alias `Op<Args...>` if it is a valid template-id, otherwise
|
||||
`boost::nonesuch`.
|
||||
|
||||
__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
|
||||
|
||||
__compat Requires C++11 variadic templates and C++11 template aliases.
|
||||
|
||||
__header `#include <boost/type_traits/detected.hpp>`
|
||||
|
||||
[endsect]
|
||||
@@ -0,0 +1,38 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:detected_or detected_or]
|
||||
|
||||
template<class Default, template<class...> class Op, class... Args>
|
||||
using detected_or = __below;
|
||||
|
||||
template<class Default, template<class...> class Op, class... Args>
|
||||
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
|
||||
|
||||
__alias An unspecified type with two public member type definitions:
|
||||
|
||||
* `value_t` is __true_type if `Op<Args...>` is a valid template-id, otherwise
|
||||
__false_type
|
||||
* `type` is `Op<Args...>` if it is a valid template-id, otherwise `Default`
|
||||
|
||||
__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
|
||||
|
||||
__compat Requires C++11 variadic templates and C++11 template aliases.
|
||||
|
||||
__header `#include <boost/type_traits/detected_or.hpp>`
|
||||
|
||||
__examples
|
||||
|
||||
template<class T>
|
||||
using difference_t = typename T::difference_type;
|
||||
|
||||
template<class T>
|
||||
using difference_type = boost::detected_or_t<std::ptrdiff_t, difference_t, T>;
|
||||
|
||||
[endsect]
|
||||
@@ -0,0 +1,42 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:is_detected is_detected]
|
||||
|
||||
template<template<class...> class Op, class... Args>
|
||||
using is_detected = __below;
|
||||
|
||||
template<template<class...> class Op, class... Args>
|
||||
constexpr bool is_detected_v = is_detected<Op, Args...>::value;
|
||||
|
||||
__alias If `Op<Args...>` is a valid template-id, aliases __true_type,
|
||||
otherwise aliases __false_type.
|
||||
|
||||
__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
|
||||
|
||||
__compat Requires C++11 variadic templates and C++11 template aliases.
|
||||
|
||||
__header `#include <boost/type_traits/is_detected.hpp>`
|
||||
|
||||
__examples
|
||||
|
||||
template<class T>
|
||||
using clear_t = decltype(boost::declval<T&>().clear());
|
||||
|
||||
template<class T>
|
||||
void clear(T& value)
|
||||
{
|
||||
if constexpr (boost::is_detected_v<clear_t, T>) {
|
||||
value.clear();
|
||||
} else {
|
||||
value = T();
|
||||
}
|
||||
}
|
||||
|
||||
[endsect]
|
||||
@@ -0,0 +1,31 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:is_detected_convertible is_detected_convertible]
|
||||
|
||||
template<class To, template<class...> class Op, class... Args>
|
||||
using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>;
|
||||
|
||||
template<class To, template<class...> class Op, class... Args>
|
||||
constexpr bool is_detected_convertible_v = is_detected_convertible<Op, Args...>::value;
|
||||
|
||||
__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
|
||||
|
||||
__compat Requires C++11 variadic templates and C++11 template aliases.
|
||||
|
||||
__header `#include <boost/type_traits/is_detected_convertible.hpp>`
|
||||
|
||||
__examples
|
||||
|
||||
template<class T>
|
||||
using size_type_t = typename T::size_type;
|
||||
|
||||
static_assert(boost::is_detected_convertible_v<std::size_t, size_type_t, T>);
|
||||
|
||||
[endsect]
|
||||
@@ -0,0 +1,31 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:is_detected_exact is_detected_exact]
|
||||
|
||||
template<class Expected, template<class...> class Op, class... Args>
|
||||
using is_detected_exact = is_same<Expected, detected_t<Op, Args...> >;
|
||||
|
||||
template<class Expected, template<class...> class Op, class... Args>
|
||||
constexpr bool is_detected_exact_v = is_detected_exact<Op, Args...>::value;
|
||||
|
||||
__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
|
||||
|
||||
__compat Requires C++11 variadic templates and C++11 template aliases.
|
||||
|
||||
__header `#include <boost/type_traits/is_detected_exact.hpp>`
|
||||
|
||||
__examples
|
||||
|
||||
template<class T>
|
||||
using difference_t = typename T::difference_type;
|
||||
|
||||
static_assert(boost::is_detected_exact_v<std::ptrdiff_t, difference_t, T>);
|
||||
|
||||
[endsect]
|
||||
@@ -0,0 +1,21 @@
|
||||
[/
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- 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:nonesuch nonesuch]
|
||||
|
||||
struct nonesuch {
|
||||
nonesuch() = delete;
|
||||
~nonesuch() = delete;
|
||||
nonesuch(const nonesuch&) = delete;
|
||||
void operator=(const nonesuch&) = delete;
|
||||
};
|
||||
|
||||
__header `#include <boost/type_traits/nonesuch.hpp>`
|
||||
|
||||
[endsect]
|
||||
@@ -31,7 +31,9 @@
|
||||
[def __true_type [link boost_typetraits.reference.integral_constant true_type]]
|
||||
[def __false_type [link boost_typetraits.reference.integral_constant false_type]]
|
||||
[def __integral_constant [link boost_typetraits.reference.integral_constant integral_constant]]
|
||||
[def __alias [*Aliases:]]
|
||||
[def __inherit [*Inherits:]]
|
||||
[def __std_paper [*C++ Standard Paper:]]
|
||||
[def __std_ref [*C++ Standard Reference:]]
|
||||
[def __header [*Header:]]
|
||||
[def __compat [*Compiler Compatibility:]]
|
||||
@@ -145,6 +147,13 @@
|
||||
[def __type_identity [link boost_typetraits.reference.type_identity type_identity]]
|
||||
[def __declval [link boost_typetraits.reference.declval declval]]
|
||||
|
||||
[def __detected [link boost_typetraits.reference.detected detected]]
|
||||
[def __detected_or [link boost_typetraits.reference.detected_or detected_or]]
|
||||
[def __is_detected [link boost_typetraits.reference.is_detected is_detected]]
|
||||
[def __is_detected_convertible [link boost_typetraits.reference.is_detected_convertible is_detected_convertible]]
|
||||
[def __is_detected_exact [link boost_typetraits.reference.is_detected_exact is_detected_exact]]
|
||||
[def __nonesuch [link boost_typetraits.reference.nonesuch nonesuch]]
|
||||
|
||||
[def __compat [*Compiler Compatibility:]]
|
||||
[template all_compilers[] __compat All current compilers are supported by this trait.]
|
||||
[template has_binary_operator_compat[] __compat Requires working SFINAE (i.e. BOOST_NO_SFINAE is not set). Only a minority of rather old compilers do not support this.]
|
||||
@@ -204,6 +213,8 @@ that is the result of the transformation.
|
||||
[include copy_cv.qbk]
|
||||
[include decay.qbk]
|
||||
[include declval.qbk]
|
||||
[include detected.qbk]
|
||||
[include detected_or.qbk]
|
||||
[include extent.qbk]
|
||||
[include floating_point_promotion.qbk]
|
||||
[include function_traits.qbk]
|
||||
@@ -289,6 +300,9 @@ See __has_trivial_constructor.
|
||||
[include is_copy_constructible.qbk]
|
||||
[include is_default_constructible.qbk]
|
||||
[include is_destructible.qbk]
|
||||
[include is_detected.qbk]
|
||||
[include is_detected_convertible.qbk]
|
||||
[include is_detected_exact.qbk]
|
||||
[include is_empty.qbk]
|
||||
[include is_enum.qbk]
|
||||
[include is_final.qbk]
|
||||
@@ -323,6 +337,7 @@ See __has_trivial_constructor.
|
||||
[include make_signed.qbk]
|
||||
[include make_unsigned.qbk]
|
||||
[include make_void.qbk]
|
||||
[include nonesuch.qbk]
|
||||
|
||||
[include promote.qbk]
|
||||
[include rank.qbk]
|
||||
|
||||
Reference in new issue
Block a user