diff --git a/doc/detected.qbk b/doc/detected.qbk index cbe4d90..59b1032 100644 --- a/doc/detected.qbk +++ b/doc/detected.qbk @@ -21,4 +21,20 @@ __compat Requires C++11 variadic templates and C++11 template aliases. __header `#include ` +__examples + +Suppose you wish to determine whether a type has a `size()` const-member function, then given the meta-functions: + + template + using size_member_tester = decltype(std::declval().size()); + + template + using size_member_t = boost::detected_t; + + +Then the type `size_member_t` is an alias for `size_member_tester` if the operation is valid, and an alias for +`boost::nonesuch` otherwise. + +See also: __is_detected, __is_detected_convertible, __is_detected_exact. + [endsect] diff --git a/doc/detected_or.qbk b/doc/detected_or.qbk index aeb8186..e036fd0 100644 --- a/doc/detected_or.qbk +++ b/doc/detected_or.qbk @@ -29,10 +29,17 @@ __header `#include ` __examples +Suppose we wish to declare a type that represents the difference between two values of type T, it should be +T::difference_type if such a type exists, or std::ptrdiff_t otherwise: + template using difference_t = typename T::difference_type; template using difference_type = boost::detected_or_t; +Now the type `difference_type` gives us what we need. + +See also: __is_detected, __is_detected_convertible, __is_detected_exact. + [endsect] diff --git a/doc/history.qbk b/doc/history.qbk index ed49f57..edfb19c 100644 --- a/doc/history.qbk +++ b/doc/history.qbk @@ -7,6 +7,10 @@ [section:history History] +[h4 Boost 1.67.0] + +* Added new traits __detected, __detected_or, __is_detected, __is_detected_convertible, and __is_detected_exact. + [h4 Boost 1.64.0] * Added new trait __make_void. diff --git a/doc/html/boost_typetraits/credits.html b/doc/html/boost_typetraits/credits.html index 741b632..cc87646 100644 --- a/doc/html/boost_typetraits/credits.html +++ b/doc/html/boost_typetraits/credits.html @@ -39,7 +39,7 @@ 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. + Ramey, Jeremy Siek, Antony Polukhin and Glen Fernandes.

Mat Marcus and Jesse Jones invented, and published diff --git a/doc/html/boost_typetraits/history.html b/doc/html/boost_typetraits/history.html index 3af9567..c133fd1 100644 --- a/doc/html/boost_typetraits/history.html +++ b/doc/html/boost_typetraits/history.html @@ -28,6 +28,18 @@

+ Boost + 1.67.0 +
+ +
+ Boost 1.64.0
@@ -35,7 +47,7 @@ Added new trait make_void.
- + Boost 1.60.0
@@ -58,7 +70,7 @@
- + Boost 1.58.0
@@ -73,7 +85,7 @@
- + Boost 1.57.0
@@ -87,7 +99,7 @@
- + Boost 1.56.0
@@ -96,7 +108,7 @@ #9474.
- + Boost 1.55.0
@@ -104,7 +116,7 @@ Added new trait is_copy_constructible.
- + Boost 1.54.0
@@ -115,7 +127,7 @@ has_trivial_move_constructor.
- + Boost 1.47.0
@@ -130,7 +142,7 @@
- + Boost 1.45.0
@@ -147,7 +159,7 @@
- + Boost 1.44.0
@@ -164,7 +176,7 @@
- + Boost 1.42.0
diff --git a/doc/html/boost_typetraits/reference.html b/doc/html/boost_typetraits/reference.html index 9ac935f..668a724 100644 --- a/doc/html/boost_typetraits/reference.html +++ b/doc/html/boost_typetraits/reference.html @@ -41,6 +41,8 @@
copy_cv
decay
declval
+
detected
+
detected_or
extent
floating_point_promotion
function_traits
@@ -115,6 +117,9 @@
is_copy_constructible
is_default_constructible
is_destructible
+
is_detected
+
is_detected_convertible
+
is_detected_exact
is_empty
is_enum
is_final
@@ -148,6 +153,7 @@
make_signed
make_unsigned
make_void
+
nonesuch
promote
rank
remove_all_extents
diff --git a/doc/html/boost_typetraits/reference/declval.html b/doc/html/boost_typetraits/reference/declval.html index 77983cc..6ee8f09 100644 --- a/doc/html/boost_typetraits/reference/declval.html +++ b/doc/html/boost_typetraits/reference/declval.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext

@@ -60,7 +60,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_typetraits/reference/detected.html b/doc/html/boost_typetraits/reference/detected.html new file mode 100644 index 0000000..b505c1b --- /dev/null +++ b/doc/html/boost_typetraits/reference/detected.html @@ -0,0 +1,88 @@ + + + +detected + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
template<template<class...> class Op, class... Args>
+using detected_t = see-below;
+
+

+ Aliases: Op<Args...> if it is a valid template-id, otherwise + boost::nonesuch. +

+

+ C++ Standard Paper: N4502 +

+

+ Compiler Compatibility: Requires C++11 variadic + templates and C++11 template aliases. +

+

+ Header: #include + <boost/type_traits/detected.hpp> +

+

+ Examples: +

+

+ Suppose you wish to determine whether a type has a size() const-member function, then given the meta-functions: +

+
template <class T>
+using size_member_tester = decltype(std::declval<const T&>().size());
+
+template <class T>
+using size_member_t = boost::detected_t<size_member_tester, T >;
+
+

+ Then the type size_member_t<T> + is an alias for size_member_tester<T> + if the operation is valid, and an alias for boost::nonesuch + otherwise. +

+

+ See also: is_detected, + is_detected_convertible, + is_detected_exact. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/detected_or.html b/doc/html/boost_typetraits/reference/detected_or.html new file mode 100644 index 0000000..7d7d381 --- /dev/null +++ b/doc/html/boost_typetraits/reference/detected_or.html @@ -0,0 +1,102 @@ + + + +detected_or + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
template<class Default, template<class...> class Op, class... Args>
+using detected_or = see-below;
+
+template<class Default, template<class...> class Op, class... Args>
+using detected_or_t = typename detected_or<Default, Op, Args...>::type;
+
+

+ Aliases: 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 +
  • +
+

+ C++ Standard Paper: N4502 +

+

+ Compiler Compatibility: Requires C++11 variadic + templates and C++11 template aliases. +

+

+ Header: #include + <boost/type_traits/detected_or.hpp> +

+

+ Examples: +

+

+ Suppose we wish to declare a type that represents the difference between + two values of type T, it should be T::difference_type if such a type exists, + or std::ptrdiff_t otherwise: +

+
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>;
+
+

+ Now the type difference_type<T> + gives us what we need. +

+

+ See also: is_detected, + is_detected_convertible, + is_detected_exact. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/extent.html b/doc/html/boost_typetraits/reference/extent.html index 97f4600..65ae9cc 100644 --- a/doc/html/boost_typetraits/reference/extent.html +++ b/doc/html/boost_typetraits/reference/extent.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
-PrevUpHomeNext +PrevUpHomeNext

@@ -107,7 +107,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_typetraits/reference/is_destructible.html b/doc/html/boost_typetraits/reference/is_destructible.html index dcbcd66..eacaf2f 100644 --- a/doc/html/boost_typetraits/reference/is_destructible.html +++ b/doc/html/boost_typetraits/reference/is_destructible.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext

@@ -63,7 +63,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_typetraits/reference/is_detected.html b/doc/html/boost_typetraits/reference/is_detected.html new file mode 100644 index 0000000..4193e77 --- /dev/null +++ b/doc/html/boost_typetraits/reference/is_detected.html @@ -0,0 +1,94 @@ + + + +is_detected + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
template<template<class...> class Op, class... Args>
+using is_detected = see-below;
+
+template<template<class...> class Op, class... Args>
+constexpr bool is_detected_v = is_detected<Op, Args...>::value;
+
+

+ Aliases: If Op<Args...> is a valid template-id, aliases true_type, + otherwise aliases false_type. +

+

+ C++ Standard Paper: N4502 +

+

+ Compiler Compatibility: Requires C++11 variadic + templates and C++11 template aliases. +

+

+ Header: #include + <boost/type_traits/is_detected.hpp> +

+

+ Examples: +

+

+ Suppose we wish to "reset" a value of type T, if the type has a + clear() + member function then we should call it, otherwise we should assign a default + constructed value: +

+
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();
+    }
+}
+
+

+ See also: is_detected_convertible, + is_detected_exact. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/is_detected_convertible.html b/doc/html/boost_typetraits/reference/is_detected_convertible.html new file mode 100644 index 0000000..2618159 --- /dev/null +++ b/doc/html/boost_typetraits/reference/is_detected_convertible.html @@ -0,0 +1,84 @@ + + + +is_detected_convertible + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
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;
+
+

+ C++ Standard Paper: N4502 +

+

+ Compiler Compatibility: Requires C++11 variadic + templates and C++11 template aliases. +

+

+ Header: #include + <boost/type_traits/is_detected_convertible.hpp> +

+

+ The type is_detected_convertible<To, Op, + Args> + is an alias for true_type + if the result of Op<Args> + is convertible to type To. + Otherwise it's the type false_type; +

+

+ 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>);
+
+

+ See also: is_detected, + is_detected_exact. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/is_detected_exact.html b/doc/html/boost_typetraits/reference/is_detected_exact.html new file mode 100644 index 0000000..cd86540 --- /dev/null +++ b/doc/html/boost_typetraits/reference/is_detected_exact.html @@ -0,0 +1,84 @@ + + + +is_detected_exact + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
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;
+
+

+ C++ Standard Paper: N4502 +

+

+ Compiler Compatibility: Requires C++11 variadic + templates and C++11 template aliases. +

+

+ Header: #include + <boost/type_traits/is_detected_exact.hpp> +

+

+ The type is_detected_exact<To, Op, + Args> + is an alias for true_type + if the result of Op<Args> + is type To. Otherwise it's + the type false_type; +

+

+ Examples: +

+
template<class T>
+using difference_t = typename T::difference_type;
+
+static_assert(boost::is_detected_exact_v<std::ptrdiff_t, difference_t, T>);
+
+

+ See also: is_detected, + is_detected_convertible. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/is_empty.html b/doc/html/boost_typetraits/reference/is_empty.html index fbff564..047c8aa 100644 --- a/doc/html/boost_typetraits/reference/is_empty.html +++ b/doc/html/boost_typetraits/reference/is_empty.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
-PrevUpHomeNext +PrevUpHomeNext

@@ -96,7 +96,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_typetraits/reference/make_void.html b/doc/html/boost_typetraits/reference/make_void.html index 13c1369..07e0a73 100644 --- a/doc/html/boost_typetraits/reference/make_void.html +++ b/doc/html/boost_typetraits/reference/make_void.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext

@@ -173,7 +173,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_typetraits/reference/nonesuch.html b/doc/html/boost_typetraits/reference/nonesuch.html new file mode 100644 index 0000000..42829f9 --- /dev/null +++ b/doc/html/boost_typetraits/reference/nonesuch.html @@ -0,0 +1,62 @@ + + + +nonesuch + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
struct nonesuch {
+    nonesuch() = delete;
+    ~nonesuch() = delete;
+    nonesuch(const nonesuch&) = delete;
+    void operator=(const nonesuch&) = delete;
+};
+
+

+ Header: #include + <boost/type_traits/nonesuch.hpp> +

+

+ Type nonesuch is a placeholder + type used when the detection idiom fails - see detected. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_typetraits/reference/promote.html b/doc/html/boost_typetraits/reference/promote.html index 585feff..bd95a9f 100644 --- a/doc/html/boost_typetraits/reference/promote.html +++ b/doc/html/boost_typetraits/reference/promote.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
-PrevUpHomeNext +PrevUpHomeNext

@@ -131,7 +131,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/index.html b/doc/html/index.html index 8aa11d8..7e6d1f5 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -97,6 +97,8 @@
copy_cv
decay
declval
+
detected
+
detected_or
extent
floating_point_promotion
function_traits
@@ -171,6 +173,9 @@
is_copy_constructible
is_default_constructible
is_destructible
+
is_detected
+
is_detected_convertible
+
is_detected_exact
is_empty
is_enum
is_final
@@ -204,6 +209,7 @@
make_signed
make_unsigned
make_void
+
nonesuch
promote
rank
remove_all_extents
diff --git a/doc/html/index/s11.html b/doc/html/index/s11.html index 026d104..5130bb1 100644 --- a/doc/html/index/s11.html +++ b/doc/html/index/s11.html @@ -24,7 +24,7 @@

-Class Index

+Class Index

A C D E F H I M N O P R T

@@ -299,10 +299,13 @@
N
-
O
diff --git a/doc/html/index/s12.html b/doc/html/index/s12.html index eba2d61..3635cf2 100644 --- a/doc/html/index/s12.html +++ b/doc/html/index/s12.html @@ -24,7 +24,7 @@

-Typedef Index

+Typedef Index

F R T V

diff --git a/doc/html/index/s13.html b/doc/html/index/s13.html index 52341d4..5e6f306 100644 --- a/doc/html/index/s13.html +++ b/doc/html/index/s13.html @@ -24,7 +24,7 @@

-Macro Index

+Macro Index

B

diff --git a/doc/html/index/s14.html b/doc/html/index/s14.html index f2fc274..b37bfe1 100644 --- a/doc/html/index/s14.html +++ b/doc/html/index/s14.html @@ -23,7 +23,7 @@

-Index

+Index

A B C D E F H I M N O P R T U V

@@ -846,10 +846,13 @@
N
-
O
diff --git a/doc/is_detected.qbk b/doc/is_detected.qbk index 4477be8..b788af5 100644 --- a/doc/is_detected.qbk +++ b/doc/is_detected.qbk @@ -26,6 +26,9 @@ __header `#include ` __examples +Suppose we wish to "reset" a value of type T, if the type has a `clear()` member function then we should call +it, otherwise we should assign a default constructed value: + template using clear_t = decltype(boost::declval().clear()); @@ -39,4 +42,6 @@ __examples } } +See also: __is_detected_convertible, __is_detected_exact. + [endsect] diff --git a/doc/is_detected_convertible.qbk b/doc/is_detected_convertible.qbk index 8c16574..0408528 100644 --- a/doc/is_detected_convertible.qbk +++ b/doc/is_detected_convertible.qbk @@ -21,6 +21,9 @@ __compat Requires C++11 variadic templates and C++11 template aliases. __header `#include ` +The type `is_detected_convertible` is an alias for __true_type if the result of +`Op` is convertible to type `To`. Otherwise it's the type __false_type; + __examples template @@ -28,4 +31,7 @@ __examples static_assert(boost::is_detected_convertible_v); +See also: __is_detected, __is_detected_exact. + + [endsect] diff --git a/doc/is_detected_exact.qbk b/doc/is_detected_exact.qbk index caef5ac..705673a 100644 --- a/doc/is_detected_exact.qbk +++ b/doc/is_detected_exact.qbk @@ -21,6 +21,10 @@ __compat Requires C++11 variadic templates and C++11 template aliases. __header `#include ` +The type `is_detected_exact` is an alias for __true_type if the result of +`Op` is type `To`. Otherwise it's the type __false_type; + + __examples template @@ -28,4 +32,6 @@ __examples static_assert(boost::is_detected_exact_v); +See also: __is_detected, __is_detected_convertible. + [endsect] diff --git a/doc/nonesuch.qbk b/doc/nonesuch.qbk index 22768c1..6809604 100644 --- a/doc/nonesuch.qbk +++ b/doc/nonesuch.qbk @@ -18,4 +18,6 @@ or copy at http://www.boost.org/LICENSE_1_0.txt). __header `#include ` +Type `nonesuch` is a placeholder type used when the detection idiom fails - see __detected. + [endsect]