diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/callable_traits/example | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/callable_traits/example')
39 files changed, 1502 insertions, 0 deletions
diff --git a/src/boost/libs/callable_traits/example/CMakeLists.txt b/src/boost/libs/callable_traits/example/CMakeLists.txt new file mode 100644 index 000000000..5a6108d28 --- /dev/null +++ b/src/boost/libs/callable_traits/example/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright Louis Dionne 2015 +# Modified Work Copyright Barrett Adair 2015-2017 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +add_custom_target(examples COMMENT "Build all the examples.") +add_dependencies(callable_traits_check examples) + +include_directories(${boost_callable_traits_SOURCE_DIR}/include) + +file(GLOB_RECURSE EXAMPLES "*.cpp") +file(GLOB_RECURSE EXPERIMENTAL_EXAMPLES "experimental*.cpp") + +if (NOT BOOST_CLBL_TRTS_BUILD_EXPERIMENTAL) + foreach(_experimental IN LISTS EXPERIMENTAL_EXAMPLES) + list(REMOVE_ITEM EXAMPLES ${_experimental}) + endforeach() +endif() + +foreach(_file IN LISTS EXAMPLES) + boost_callable_traits_target_name_for(_target "${_file}") + add_executable(${_target} EXCLUDE_FROM_ALL "${_file}") + boost_callable_traits_add_test(${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target}) + add_dependencies(examples ${_target}) +endforeach() diff --git a/src/boost/libs/callable_traits/example/Jamfile.v2 b/src/boost/libs/callable_traits/example/Jamfile.v2 new file mode 100644 index 000000000..d94b84f65 --- /dev/null +++ b/src/boost/libs/callable_traits/example/Jamfile.v2 @@ -0,0 +1,19 @@ +# Copyright Louis Dionne 2013-2016 +# Modified Work Copyright Barrett Adair 2016-2017 +# Copyright 2017 Peter Dimov +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +import testing ; + +project : + requirements + <toolset>clang:<cxxflags>"-pedantic -Wall -Wextra" + <toolset>darwin:<cxxflags>"-pedantic -Wall -Wextra" +; + +for local source in [ glob *.cpp ] +{ + run $(source) ; +} diff --git a/src/boost/libs/callable_traits/example/add_member_const.cpp b/src/boost/libs/callable_traits/example/add_member_const.cpp new file mode 100644 index 000000000..83dba2a96 --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_member_const.cpp @@ -0,0 +1,49 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ add_member_const +#include <type_traits> +#include <boost/callable_traits/add_member_const.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = int(foo::*)(); + using expect = int(foo::*)() const; + using test = ct::add_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_const_t doesn't change anything when + // the function type is already const. + using pmf = int(foo::*)() const &&; + using expect = int(foo::*)() const &&; + using test = ct::add_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() volatile &; + using expect = int(foo::*)() const volatile &; + using test = ct::add_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_const_t can also be used with "abominable" + // function types. + using f = int(); + using expect = int() const; + using test = ct::add_member_const_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/add_member_cv.cpp b/src/boost/libs/callable_traits/example/add_member_cv.cpp new file mode 100644 index 000000000..77997688e --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_member_cv.cpp @@ -0,0 +1,49 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ add_member_cv +#include <type_traits> +#include <boost/callable_traits/add_member_cv.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = void(foo::*)(); + using expect = void(foo::*)() const volatile; + using test = ct::add_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_cv_t doesn't change anything when + // the function type is already cv-qualified. + using pmf = void(foo::*)() const volatile &&; + using expect = void(foo::*)() const volatile &&; + using test = ct::add_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = void(foo::*)() volatile &; + using expect = void(foo::*)() const volatile &; + using test = ct::add_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_cv_t can also be used with "abominable" + // function types. + using f = void(); + using expect = void() const volatile; + using test = ct::add_member_cv_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/add_member_lvalue_reference.cpp b/src/boost/libs/callable_traits/example/add_member_lvalue_reference.cpp new file mode 100644 index 000000000..8d168a295 --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_member_lvalue_reference.cpp @@ -0,0 +1,53 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ add_member_lvalue_reference +#include <type_traits> +#include <boost/callable_traits/add_member_lvalue_reference.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = void(foo::*)(); + using expect = void(foo::*)() &; + using test = ct::add_member_lvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_lvalue_reference_t doesn't change anything when + // the function type already has an lvalue qualifier. + using pmf = void(foo::*)() &; + using expect = void(foo::*)() &; + using test = ct::add_member_lvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_lvalue_reference_t models C++11 reference collapsing + // rules, so that adding an lvalue qualifier to an + // rvalue-qualified type will force the lvalue. + using pmf = void(foo::*)() &&; + using expect = void(foo::*)() &; + using test = ct::add_member_lvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_lvalue_reference_t can also be used to create "abominable" + // function types. + using f = void(); + using expect = void() &; + using test = ct::add_member_lvalue_reference_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} + +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/add_member_rvalue_reference.cpp b/src/boost/libs/callable_traits/example/add_member_rvalue_reference.cpp new file mode 100644 index 000000000..81ecf257c --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_member_rvalue_reference.cpp @@ -0,0 +1,53 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ add_member_rvalue_reference +#include <type_traits> +#include <boost/callable_traits/add_member_rvalue_reference.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = void(foo::*)(); + using expect = void(foo::*)() &&; + using test = ct::add_member_rvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_rvalue_reference_t doesn't change anything when + // the function type already has an rvalue qualifier. + using pmf = void(foo::*)() &&; + using expect = void(foo::*)() &&; + using test = ct::add_member_rvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_rvalue_reference_t models C++11 reference collapsing + // rules, so that adding an rvalue qualifier to an + // lvalue-qualified type will not change anything. + using pmf = void(foo::*)() const &; + using expect = void(foo::*)() const &; + using test = ct::add_member_rvalue_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_rvalue_reference_t can also be used with "abominable" + // function types. + using f = void() const; + using expect = void() const &&; + using test = ct::add_member_rvalue_reference_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} + +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/add_member_volatile.cpp b/src/boost/libs/callable_traits/example/add_member_volatile.cpp new file mode 100644 index 000000000..ffddcbfe5 --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_member_volatile.cpp @@ -0,0 +1,50 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ add_member_volatile +#include <type_traits> +#include <boost/callable_traits/add_member_volatile.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = void(foo::*)(); + using expect = void(foo::*)() volatile; + using test = ct::add_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_volatile_t doesn't change anything when + // the function type is already volatile. + using pmf = void(foo::*)() volatile &&; + using expect = void(foo::*)() volatile &&; + using test = ct::add_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = void(foo::*)() const &; + using expect = void(foo::*)() const volatile &; + using test = ct::add_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + // add_member_volatile_t can also be used with "abominable" + // function types. + using f = void(); + using expect = void() volatile; + using test = ct::add_member_volatile_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} + +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/add_noexcept.cpp b/src/boost/libs/callable_traits/example/add_noexcept.cpp new file mode 100644 index 000000000..fa5ff9066 --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_noexcept.cpp @@ -0,0 +1,29 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES +int main(){} +#else + +//[ add_noexcept +#include <type_traits> +#include <boost/callable_traits/add_noexcept.hpp> + +using boost::callable_traits::add_noexcept_t; + +static_assert(std::is_same< + add_noexcept_t<int()>, + int() noexcept +>{}, ""); + +int main() {} + +//] +#endif + diff --git a/src/boost/libs/callable_traits/example/add_transaction_safe.cpp b/src/boost/libs/callable_traits/example/add_transaction_safe.cpp new file mode 100644 index 000000000..92a6ea717 --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_transaction_safe.cpp @@ -0,0 +1,30 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE +int main(){} +#else + +//[ add_transaction_safe +#include <type_traits> +#include <boost/callable_traits/add_transaction_safe.hpp> + +using boost::callable_traits::add_transaction_safe_t; + +using not_safe = int(); +using safe = int() transaction_safe; +using safe_added = add_transaction_safe_t<not_safe>; + +static_assert(std::is_same<safe, safe_added>{}, ""); + +int main() {} + +//] +#endif + diff --git a/src/boost/libs/callable_traits/example/add_varargs.cpp b/src/boost/libs/callable_traits/example/add_varargs.cpp new file mode 100644 index 000000000..8538c00bd --- /dev/null +++ b/src/boost/libs/callable_traits/example/add_varargs.cpp @@ -0,0 +1,44 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +//[ add_varargs +#include <type_traits> +#include <boost/callable_traits/add_varargs.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using f = void(int); + using expect = void(int, ...); + using test = ct::add_varargs_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using fp = void(*)(); + using expect = void(*)(...); + using test = ct::add_varargs_t<fp>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using fr = void(&)(const char*); + using expect = void(&)(const char*, ...); + using test = ct::add_varargs_t<fr>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = void(foo::*)() const; + using expect = void(foo::*)(...) const; + using test = ct::add_varargs_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + + // add_varargs_t doesn't change anything when + // the type already has varargs. + using twice = ct::add_varargs_t<test>; + static_assert(std::is_same<test, twice>::value, ""); + } +} +//] diff --git a/src/boost/libs/callable_traits/example/apply_member_pointer.cpp b/src/boost/libs/callable_traits/example/apply_member_pointer.cpp new file mode 100644 index 000000000..63a944d39 --- /dev/null +++ b/src/boost/libs/callable_traits/example/apply_member_pointer.cpp @@ -0,0 +1,94 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ apply_member_pointer +#include <type_traits> +#include <boost/callable_traits/apply_member_pointer.hpp> + +namespace ct = boost::callable_traits; + +struct foo; +struct bar; + +int main() { + + { + // function type -> member function pointer type + using f = int(int); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = int(foo::*)(int); + static_assert(std::is_same<g, expect>::value, ""); + } + + { + // function pointer type (unqualified) -> member function pointer type + using f = int(*)(); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = int(foo::*)(); + static_assert(std::is_same<g, expect>::value, ""); + } + + + { + // function pointer type (qualified) -> member data pointer type + + // Look out for cases like these two. If the input type to apply_member_pointer + // is a ``[*qualified]`` function pointer type, then the aliased type is a member data + // pointer to a ``[*qualified function pointer]``. + + { + using f = int(*&)(); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = int (* foo::*)(); + static_assert(std::is_same<g, expect>::value, ""); + } + + { + using f = int(* const)(); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = int (* const foo::*)(); + static_assert(std::is_same<g, expect>::value, ""); + } + } + + { + // function reference type -> member function pointer type + using f = void(&)(); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = void(foo::*)(); + static_assert(std::is_same<g, expect>::value, ""); + } + + { + // member function pointer type -> member function pointer type + // (note the different parent class) + using f = int(bar::*)() const; + using g = ct::apply_member_pointer_t<f, foo>; + using expect = int(foo::*)() const; + static_assert(std::is_same<g, expect>::value, ""); + } + + { + // non-callable type -> member data pointer type + using g = ct::apply_member_pointer_t<int, foo>; + using expect = int foo::*; + static_assert(std::is_same<g, expect>::value, ""); + } + + + { + // function object type -> member data pointer type + // the same is true for lambdas and generic lambdas + auto lambda = [](){}; + using f = decltype(lambda); + using g = ct::apply_member_pointer_t<f, foo>; + using expect = f foo::*; + static_assert(std::is_same<g, expect>::value, ""); + } +} +//] + diff --git a/src/boost/libs/callable_traits/example/args.cpp b/src/boost/libs/callable_traits/example/args.cpp new file mode 100644 index 000000000..9e0ef2d9a --- /dev/null +++ b/src/boost/libs/callable_traits/example/args.cpp @@ -0,0 +1,69 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS +int main(){ return 0; } +#else + +//[ args +#include <type_traits> +#include <memory> +#include <boost/callable_traits.hpp> + +namespace ct = boost::callable_traits; + +template<typename T, typename Expect> +void test(){ + using args_t = ct::args_t<T>; + static_assert(std::is_same<args_t, Expect>::value, ""); +} + +int main() { + + { + auto lamda = [](int, float&, const char*){}; + using lam = decltype(lamda); + using expect = std::tuple<int, float&, const char*>; + + test<lam, expect>(); + } + + { + struct foo; + using pmf = void(foo::*)(int, float&, const char*); + using expect = std::tuple<foo&, int, float&, const char*>; + + test<pmf, expect>(); + } + + { + using function_ptr = void(*)(int, float&, const char*); + using expect = std::tuple<int, float&, const char*>; + test<function_ptr, expect>(); + } + + { + using function_ref = void(&)(int, float&, const char*); + using expect = std::tuple<int, float&, const char*>; + test<function_ref, expect>(); + } + + { + using function = void(int, float&, const char*); + using expect = std::tuple<int, float&, const char*>; + test<function, expect>(); + } + + { + using abominable = void(int, float&, const char*) const; + using expect = std::tuple<int, float&, const char*>; + test<abominable, expect>(); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS diff --git a/src/boost/libs/callable_traits/example/class_of.cpp b/src/boost/libs/callable_traits/example/class_of.cpp new file mode 100644 index 000000000..9a75977e1 --- /dev/null +++ b/src/boost/libs/callable_traits/example/class_of.cpp @@ -0,0 +1,22 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +//[ class_of +#include <type_traits> +#include <boost/callable_traits/class_of.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(std::is_same<foo, ct::class_of_t<int(foo::*)()>>::value, ""); +static_assert(std::is_same<foo, ct::class_of_t<int foo::*>>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/function_type.cpp b/src/boost/libs/callable_traits/example/function_type.cpp new file mode 100644 index 000000000..8047bbb80 --- /dev/null +++ b/src/boost/libs/callable_traits/example/function_type.cpp @@ -0,0 +1,48 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS +int main(){ return 0; } +#else + +//[ function_type +#include <type_traits> +#include <boost/callable_traits.hpp> + +namespace ct = boost::callable_traits; + +template<typename T> +void test(){ + + // this example shows how boost::callable_traits::function_type_t + // bevaves consistently for many different types + using type = ct::function_type_t<T>; + using expect = void(int, float&, const char*); + static_assert(std::is_same<expect, type>{}, ""); +} + +int main() { + + auto lamda = [](int, float&, const char*){}; + using lam = decltype(lamda); + test<lam>(); + + using function_ptr = void(*)(int, float&, const char*); + test<function_ptr>(); + + using function_ref = void(&)(int, float&, const char*); + test<function_ref>(); + + using function = void(int, float&, const char*); + test<function>(); + + using abominable = void(int, float&, const char*) const; + test<abominable>(); +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS diff --git a/src/boost/libs/callable_traits/example/function_types_remove_const_comparison.cpp b/src/boost/libs/callable_traits/example/function_types_remove_const_comparison.cpp new file mode 100644 index 000000000..2f37f0922 --- /dev/null +++ b/src/boost/libs/callable_traits/example/function_types_remove_const_comparison.cpp @@ -0,0 +1,21 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +//[ function_types_remove_const_comparison +#include <type_traits> +#include <boost/callable_traits/remove_member_const.hpp> + +struct foo { + void bar() const {} +}; + +using const_removed = boost::callable_traits::remove_member_const_t<decltype(&foo::bar)>; + +static_assert(std::is_same<const_removed, void(foo::*)()>::value, ""); + +int main(){} + +//] diff --git a/src/boost/libs/callable_traits/example/has_member_qualifiers.cpp b/src/boost/libs/callable_traits/example/has_member_qualifiers.cpp new file mode 100644 index 000000000..79378c3a3 --- /dev/null +++ b/src/boost/libs/callable_traits/example/has_member_qualifiers.cpp @@ -0,0 +1,21 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ has_member_qualifiers +#include <type_traits> +#include <boost/callable_traits/has_member_qualifiers.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(ct::has_member_qualifiers<int(foo::*)() const>::value, ""); +static_assert(ct::has_member_qualifiers<int(foo::*)() volatile>::value, ""); +static_assert(!ct::has_member_qualifiers<int(foo::*)()>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/has_varargs.cpp b/src/boost/libs/callable_traits/example/has_varargs.cpp new file mode 100644 index 000000000..1dd66fd44 --- /dev/null +++ b/src/boost/libs/callable_traits/example/has_varargs.cpp @@ -0,0 +1,24 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#ifdef BOOST_CLBL_TRTS_MSVC +// MSVC requires __cdecl for varargs, and I don't want to clutter the example +int main(){} +#else + +//[ has_varargs +#include <type_traits> +#include <boost/callable_traits/has_varargs.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::has_varargs<int(...)>::value, ""); +static_assert(!ct::has_varargs<int()>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/has_void_return.cpp b/src/boost/libs/callable_traits/example/has_void_return.cpp new file mode 100644 index 000000000..3e14561a2 --- /dev/null +++ b/src/boost/libs/callable_traits/example/has_void_return.cpp @@ -0,0 +1,18 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ has_void_return +#include <type_traits> +#include <boost/callable_traits/has_void_return.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::has_void_return<void()>::value, ""); +static_assert(!ct::has_void_return<int()>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/intro.cpp b/src/boost/libs/callable_traits/example/intro.cpp new file mode 100644 index 000000000..a1e05096d --- /dev/null +++ b/src/boost/libs/callable_traits/example/intro.cpp @@ -0,0 +1,62 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES +int main(){ return 0; } +#else + +//[ intro +#include <type_traits> +#include <tuple> +#include <boost/callable_traits.hpp> + +namespace ct = boost::callable_traits; + +// This function template helps keep our example code neat +template<typename A, typename B> +void assert_same(){ static_assert(std::is_same<A, B>::value, ""); } + +// foo is a function object +struct foo { + void operator()(int, char, float) const {} +}; + +int main() { + + // Use args_t to retrieve a parameter list as a std::tuple: + assert_same< + ct::args_t<foo>, + std::tuple<int, char, float> + >(); + + // has_void_return lets us perform a quick check for a void return type + static_assert(ct::has_void_return<foo>::value, ""); + + // Detect C-style variadics (ellipses) in a signature (e.g. printf) + static_assert(!ct::has_varargs<foo>::value, ""); + + // pmf is a pointer-to-member function: void (foo::*)(int, char, float) const + using pmf = decltype(&foo::operator()); + + // remove_member_const_t lets you remove the const member qualifier + assert_same< + ct::remove_member_const_t<pmf>, + void (foo::*)(int, char, float) /*no const!*/ + >(); + + // Conversely, add_member_const_t adds a const member qualifier + assert_same< + pmf, + ct::add_member_const_t<void (foo::*)(int, char, float)> + >(); + + // is_const_member_v checks for the presence of member const + static_assert(ct::is_const_member<pmf>::value, ""); +} + +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_const_member.cpp b/src/boost/libs/callable_traits/example/is_const_member.cpp new file mode 100644 index 000000000..110e76309 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_const_member.cpp @@ -0,0 +1,20 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ is_const_member +#include <type_traits> +#include <boost/callable_traits/is_const_member.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(ct::is_const_member<int(foo::*)() const>::value, ""); +static_assert(!ct::is_const_member<int(foo::*)()>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/is_cv_member.cpp b/src/boost/libs/callable_traits/example/is_cv_member.cpp new file mode 100644 index 000000000..638c219e4 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_cv_member.cpp @@ -0,0 +1,22 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ is_cv_member +#include <type_traits> +#include <boost/callable_traits/is_cv_member.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(ct::is_cv_member<int(foo::*)() const volatile>::value, ""); +static_assert(!ct::is_cv_member<int(foo::*)()>::value, ""); +static_assert(!ct::is_cv_member<int(foo::*)() const>::value, ""); +static_assert(!ct::is_cv_member<int(foo::*)() volatile>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/is_invocable.cpp b/src/boost/libs/callable_traits/example/is_invocable.cpp new file mode 100644 index 000000000..a374de01f --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_invocable.cpp @@ -0,0 +1,24 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +//[ is_invocable +#include <type_traits> +#include <boost/callable_traits/is_invocable.hpp> + +namespace ct = boost::callable_traits; + +struct foo { + template<typename T> + typename std::enable_if<std::is_integral<T>::value>::type + operator()(T){} +}; + +static_assert(ct::is_invocable<foo, int>::value, ""); +static_assert(!ct::is_invocable<foo, double>::value, ""); + +int main() {} +//] diff --git a/src/boost/libs/callable_traits/example/is_lvalue_reference_member.cpp b/src/boost/libs/callable_traits/example/is_lvalue_reference_member.cpp new file mode 100644 index 000000000..4cc96e850 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_lvalue_reference_member.cpp @@ -0,0 +1,32 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ is_lvalue_reference_member +#include <type_traits> +#include <boost/callable_traits/is_lvalue_reference_member.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::is_lvalue_reference_member<int()&>::value, ""); +static_assert(!ct::is_lvalue_reference_member<int()&&>::value, ""); +static_assert(!ct::is_lvalue_reference_member<int()>::value, ""); + +struct foo; + +static_assert(ct::is_lvalue_reference_member<int(foo::*)()&>::value, ""); +static_assert(!ct::is_lvalue_reference_member<int(foo::*)()&&>::value, ""); +static_assert(!ct::is_lvalue_reference_member<int(foo::*)()>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_noexcept.cpp b/src/boost/libs/callable_traits/example/is_noexcept.cpp new file mode 100644 index 000000000..0c4e83887 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_noexcept.cpp @@ -0,0 +1,33 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES +int main(){} +#else + +//[ is_noexcept +#include <boost/callable_traits/is_noexcept.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(ct::is_noexcept<int() noexcept>::value, ""); +static_assert(ct::is_noexcept<int(*)() noexcept>::value, ""); +static_assert(ct::is_noexcept<int(&)() noexcept>::value, ""); +static_assert(ct::is_noexcept<int(foo::*)() const noexcept>::value, ""); + +static_assert(!ct::is_noexcept<int()>::value, ""); +static_assert(!ct::is_noexcept<int(*)()>::value, ""); +static_assert(!ct::is_noexcept<int(&)()>::value, ""); +static_assert(!ct::is_noexcept<int(foo::*)() const>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_reference_member.cpp b/src/boost/libs/callable_traits/example/is_reference_member.cpp new file mode 100644 index 000000000..480fb5588 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_reference_member.cpp @@ -0,0 +1,32 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ is_reference_member +#include <type_traits> +#include <boost/callable_traits/is_reference_member.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::is_reference_member<int()&>::value, ""); +static_assert(ct::is_reference_member<int()&&>::value, ""); +static_assert(!ct::is_reference_member<int()>::value, ""); + +struct foo; + +static_assert(ct::is_reference_member<int(foo::*)()&>::value, ""); +static_assert(ct::is_reference_member<int(foo::*)()&&>::value, ""); +static_assert(!ct::is_reference_member<int(foo::*)()>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_rvalue_reference_member.cpp b/src/boost/libs/callable_traits/example/is_rvalue_reference_member.cpp new file mode 100644 index 000000000..162c12375 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_rvalue_reference_member.cpp @@ -0,0 +1,32 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ is_rvalue_reference_member +#include <type_traits> +#include <boost/callable_traits/is_rvalue_reference_member.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::is_rvalue_reference_member<int()&&>::value, ""); +static_assert(!ct::is_rvalue_reference_member<int()&>::value, ""); +static_assert(!ct::is_rvalue_reference_member<int()>::value, ""); + +struct foo; + +static_assert(ct::is_rvalue_reference_member<int(foo::*)()&&>::value, ""); +static_assert(!ct::is_rvalue_reference_member<int(foo::*)()&>::value, ""); +static_assert(!ct::is_rvalue_reference_member<int(foo::*)()>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_transaction_safe.cpp b/src/boost/libs/callable_traits/example/is_transaction_safe.cpp new file mode 100644 index 000000000..26ae8d9b4 --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_transaction_safe.cpp @@ -0,0 +1,33 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE +int main(){} +#else + +//[ is_transaction_safe +#include <boost/callable_traits/is_transaction_safe.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(ct::is_transaction_safe<int() transaction_safe>::value, ""); +static_assert(ct::is_transaction_safe<int(*)() transaction_safe>::value, ""); +static_assert(ct::is_transaction_safe<int(&)() transaction_safe>::value, ""); +static_assert(ct::is_transaction_safe<int(foo::*)() const transaction_safe>::value, ""); + +static_assert(!ct::is_transaction_safe<int()>::value, ""); +static_assert(!ct::is_transaction_safe<int(*)()>::value, ""); +static_assert(!ct::is_transaction_safe<int(&)()>::value, ""); +static_assert(!ct::is_transaction_safe<int(foo::*)() const>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/is_volatile_member.cpp b/src/boost/libs/callable_traits/example/is_volatile_member.cpp new file mode 100644 index 000000000..91dd3993c --- /dev/null +++ b/src/boost/libs/callable_traits/example/is_volatile_member.cpp @@ -0,0 +1,32 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS +int main(){ return 0; } +#else + +//[ is_volatile_member +#include <type_traits> +#include <boost/callable_traits/is_volatile_member.hpp> + +namespace ct = boost::callable_traits; + +static_assert(ct::is_volatile_member<int() volatile>::value, ""); +static_assert(ct::is_volatile_member<int() const volatile>::value, ""); +static_assert(!ct::is_volatile_member<int()>::value, ""); + +struct foo; + +static_assert(ct::is_volatile_member<int(foo::*)() volatile>::value, ""); +static_assert(!ct::is_volatile_member<int(foo::*)() const>::value, ""); +static_assert(!ct::is_volatile_member<int(foo::*)()>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/overview.cpp b/src/boost/libs/callable_traits/example/overview.cpp new file mode 100644 index 000000000..a5186bf9c --- /dev/null +++ b/src/boost/libs/callable_traits/example/overview.cpp @@ -0,0 +1,78 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS +int main(){} +#else + +//[ overview +#include <boost/callable_traits.hpp> + +#include <type_traits> +#include <tuple> + +using std::is_same; +using std::tuple; + +using namespace boost::callable_traits; + +struct number { + int value; + int add(int n) const { return value + n; } +}; + +using pmf = decltype(&number::add); + +//` Manipulate member functions pointers with ease: +static_assert(is_same< + remove_member_const_t<pmf>, + int(number::*)(int) +>{}, ""); + +static_assert(is_same< + add_member_volatile_t<pmf>, + int(number::*)(int) const volatile +>{}, ""); + +static_assert(is_same< + class_of_t<pmf>, + number +>{}, ""); + +//` INVOKE-aware metafunctions: + +static_assert(is_same< + args_t<pmf>, + tuple<const number&, int> +>{}, ""); + +static_assert(is_same< + return_type_t<pmf>, + int +>{}, ""); + +static_assert(is_same< + function_type_t<pmf>, + int(const number&, int) +>{}, ""); + +static_assert(is_same< + qualified_class_of_t<pmf>, + const number& +>{}, ""); + +//` Here are a few other trait examples: +static_assert(is_const_member<pmf>{}, ""); +static_assert(!is_volatile_member<pmf>{}, ""); +static_assert(!has_void_return<pmf>{}, ""); +static_assert(!has_varargs<pmf>{}, ""); + +//] + +int main() {} + +#endif diff --git a/src/boost/libs/callable_traits/example/qualified_class_of.cpp b/src/boost/libs/callable_traits/example/qualified_class_of.cpp new file mode 100644 index 000000000..049f87e4f --- /dev/null +++ b/src/boost/libs/callable_traits/example/qualified_class_of.cpp @@ -0,0 +1,32 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ qualified_class_of +#include <type_traits> +#include <boost/callable_traits/qualified_class_of.hpp> + +namespace ct = boost::callable_traits; + +struct foo; + +static_assert(std::is_same<foo &, + ct::qualified_class_of_t<int(foo::*)()>>::value, ""); + +static_assert(std::is_same<foo const &, + ct::qualified_class_of_t<int(foo::*)() const>>::value, ""); + +static_assert(std::is_same<foo volatile &&, + ct::qualified_class_of_t<int(foo::*)() volatile &&>>::value, ""); + +int main() {} +//] +#endif diff --git a/src/boost/libs/callable_traits/example/remove_member_const.cpp b/src/boost/libs/callable_traits/example/remove_member_const.cpp new file mode 100644 index 000000000..c0a97a5c4 --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_member_const.cpp @@ -0,0 +1,45 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ remove_member_const +#include <type_traits> +#include <boost/callable_traits/remove_member_const.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = int(foo::*)() const; + using expect = int(foo::*)(); + using test = ct::remove_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const &&; + using expect = int(foo::*)() &&; + using test = ct::remove_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const volatile &; + using expect = int(foo::*)() volatile &; + using test = ct::remove_member_const_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using f = int() const; + using expect = int(); + using test = ct::remove_member_const_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/remove_member_cv.cpp b/src/boost/libs/callable_traits/example/remove_member_cv.cpp new file mode 100644 index 000000000..3d741fcca --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_member_cv.cpp @@ -0,0 +1,45 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ remove_member_cv +#include <type_traits> +#include <boost/callable_traits/remove_member_cv.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = int(foo::*)() const volatile; + using expect = int(foo::*)(); + using test = ct::remove_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const &&; + using expect = int(foo::*)() &&; + using test = ct::remove_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const volatile &; + using expect = int(foo::*)() &; + using test = ct::remove_member_cv_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using f = int() const volatile; + using expect = int(); + using test = ct::remove_member_cv_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/remove_member_reference.cpp b/src/boost/libs/callable_traits/example/remove_member_reference.cpp new file mode 100644 index 000000000..b08a8c6a2 --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_member_reference.cpp @@ -0,0 +1,45 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ remove_member_reference +#include <type_traits> +#include <boost/callable_traits/remove_member_reference.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = int(foo::*)() &; + using expect = int(foo::*)(); + using test = ct::remove_member_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const &&; + using expect = int(foo::*)() const; + using test = ct::remove_member_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() const volatile &; + using expect = int(foo::*)() const volatile; + using test = ct::remove_member_reference_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using f = int() &&; + using expect = int(); + using test = ct::remove_member_reference_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/remove_member_volatile.cpp b/src/boost/libs/callable_traits/example/remove_member_volatile.cpp new file mode 100644 index 000000000..2d3fa388d --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_member_volatile.cpp @@ -0,0 +1,45 @@ +/*<- +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else + +//[ remove_member_volatile +#include <type_traits> +#include <boost/callable_traits/remove_member_volatile.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using pmf = int(foo::*)() const volatile; + using expect = int(foo::*)() const; + using test = ct::remove_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() volatile &&; + using expect = int(foo::*)() &&; + using test = ct::remove_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = int(foo::*)() volatile &; + using expect = int(foo::*)() &; + using test = ct::remove_member_volatile_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using f = int() const volatile; + using expect = int() const; + using test = ct::remove_member_volatile_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS diff --git a/src/boost/libs/callable_traits/example/remove_noexcept.cpp b/src/boost/libs/callable_traits/example/remove_noexcept.cpp new file mode 100644 index 000000000..d3b11c5e6 --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_noexcept.cpp @@ -0,0 +1,29 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES +int main(){} +#else + +//[ remove_noexcept +#include <type_traits> +#include <boost/callable_traits/remove_noexcept.hpp> + +using boost::callable_traits::remove_noexcept_t; + +static_assert(std::is_same< + remove_noexcept_t<int() noexcept>, + int() +>{}, ""); + +int main() {} + +//] +#endif + diff --git a/src/boost/libs/callable_traits/example/remove_transaction_safe.cpp b/src/boost/libs/callable_traits/example/remove_transaction_safe.cpp new file mode 100644 index 000000000..bdf4f1340 --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_transaction_safe.cpp @@ -0,0 +1,29 @@ +/*<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> + +#ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE +int main(){} +#else + +//[ remove_transaction_safe +#include <type_traits> +#include <boost/callable_traits/remove_transaction_safe.hpp> + +namespace ct = boost::callable_traits; + +using ts = int() transaction_safe; +using not_ts = int(); +using ts_removed = ct::remove_transaction_safe_t<ts>; + +static_assert(std::is_same<not_ts, ts_removed>{}, ""); + +int main() {} +//] +#endif //#ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE + diff --git a/src/boost/libs/callable_traits/example/remove_varargs.cpp b/src/boost/libs/callable_traits/example/remove_varargs.cpp new file mode 100644 index 000000000..47194e08c --- /dev/null +++ b/src/boost/libs/callable_traits/example/remove_varargs.cpp @@ -0,0 +1,41 @@ +/*<- + +Copyright Barrett Adair 2016-2017 + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ + +//[ remove_varargs +#include <type_traits> +#include <boost/callable_traits/remove_varargs.hpp> + +namespace ct = boost::callable_traits; + +struct foo {}; + +int main() { + + { + using f = void(int, ...); + using expect = void(int); + using test = ct::remove_varargs_t<f>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using fp = void(*)(...); + using expect = void(*)(); + using test = ct::remove_varargs_t<fp>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using fr = void(&)(const char*, ...); + using expect = void(&)(const char*); + using test = ct::remove_varargs_t<fr>; + static_assert(std::is_same<test, expect>::value, ""); + } { + using pmf = void(foo::*)(...) const; + using expect = void(foo::*)() const; + using test = ct::remove_varargs_t<pmf>; + static_assert(std::is_same<test, expect>::value, ""); + } +} +//] diff --git a/src/boost/libs/callable_traits/example/return_type.cpp b/src/boost/libs/callable_traits/example/return_type.cpp new file mode 100644 index 000000000..bc3a5cef4 --- /dev/null +++ b/src/boost/libs/callable_traits/example/return_type.cpp @@ -0,0 +1,42 @@ +/*!<- +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +->*/ + +#include <boost/callable_traits/detail/config.hpp> +#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS +int main(){ return 0; } +#else + +//[ return_type +#include <type_traits> +#include <boost/callable_traits.hpp> + +namespace ct = boost::callable_traits; + +using expect = int; + +struct foo; + +template<typename T> +void test() { + using result = ct::return_type_t<T>; + static_assert(std::is_same<expect, result>{}, ""); +} + +int main() { + + test<int()>(); + test<int(*)()>(); + test<int(&)()>(); + test<int() const>(); + test<int(foo::*)() const>(); + + auto x = []() -> int { return 0; }; + + test<decltype(x)>(); +} +//] +#endif //#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS diff --git a/src/boost/libs/callable_traits/example/void.cpp b/src/boost/libs/callable_traits/example/void.cpp new file mode 100644 index 000000000..75fc8eee2 --- /dev/null +++ b/src/boost/libs/callable_traits/example/void.cpp @@ -0,0 +1,31 @@ +/* + +Copyright Barrett Adair 2016-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#include <type_traits> +#include <functional> +#include <tuple> +#include <boost/callable_traits.hpp> + +struct foo { + void operator()() const {} +}; + +namespace ct = boost::callable_traits; + +int main() { + + using args = ct::args_t<foo>; + using expected_args = std::tuple<>; + static_assert(std::is_same<args, expected_args>{}, ""); + + using signature = ct::function_type_t<foo>; + using expected_signature = void(); + static_assert(std::is_same<signature, expected_signature>{}, ""); + + return 0; +} |