From b4876a158a85e5c4e31fdbd83afda24bc4d5ed07 Mon Sep 17 00:00:00 2001 From: badair Date: Wed, 30 Mar 2016 23:29:47 -0500 Subject: [PATCH] starting quickbook docs --- doc/Jamfile.v2 | 20 ++++ doc/callable_traits.qbk | 110 ++++++++++++++++++ .../detail/function_object.hpp | 8 +- include/callable_traits/detail/pmf.hpp | 15 ++- test/Jamfile.v2 | 42 +++++++ 5 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 doc/Jamfile.v2 create mode 100644 doc/callable_traits.qbk create mode 100644 test/Jamfile.v2 diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..2863840 --- /dev/null +++ b/doc/Jamfile.v2 @@ -0,0 +1,20 @@ +# Copyright Peder Holt 2005. +# Copyright Modified Work Barrett Adair 2016. +# 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) + +using quickbook ; + +xml callable_traits : callable_traits.qbk ; +boostbook standalone + : + callable_traits + : + boost.root=../../../.. + nav.layout=none + navig.graphics=0 + ; + +install html : ../../../doc/src/boostbook.css ; +install ../ : ../../../boost.png ; \ No newline at end of file diff --git a/doc/callable_traits.qbk b/doc/callable_traits.qbk new file mode 100644 index 0000000..96d70bd --- /dev/null +++ b/doc/callable_traits.qbk @@ -0,0 +1,110 @@ +[library CallableTraits + [authors [Adair, Barrett]] + [copyright 2016 Barrett Adair] + [license + 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 + ) + ] + [id callable_traits] + [last-revision $Date$] +] + +[section:moti Motivation] + +[c++] + +The complexity of callable types in C++ is extensive: + +*function types +*function pointers +*function references +*objects with `operator()` +*objects with function pointer conversions +*[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0172r0.html "abominable" function types] +*pointers to member data +*pointers to member functions +*qualified overloads of member functions: `const`, `volatile`, `&`, `&&` +*C-style varargs (`...`) +*calling conventions (`__cdecl`, `__stdcall`, `__fastcall`, `pascal`, etc.) +*`noexcept` (part of the function type system in C++17) + +CallableTraits provides a comprehensive, uniform and modern type-level interface for the manipulation and inspection of callable types in C++. CallableTraits aims to provide such an exhaustive interface for the features listed above that the libary writer will *never again be required to specialize templates for callable types*. In other words, library writers should never need to write a template like this one:, for *any* reason: + + template + struct foo{ + //... + }; + +Several library solutions exist to manipulate these types, or to abstract away their complexities. However, in the opinion of the author, these solutions are often inflexible and lacking in features, especially in regard to function objects and lambdas. In many cases, the CallableTraits interface allow authors of generic code to treat these types as interchangeable: function objects, function pointers, function references, function types, abominable function types, member function pointers, member data pointers, and references/pointers/smart pointers to all of the above (whenever applicable). + +CallableTraits contains the following type traits and metafunctions (psuedo-code): + +[*`std::integral_constant` constexpr functions] + +* `can_invoke(T&&, Args&&...)` +* `can_invoke_constexpr(T&&, Args&&...)` +* `is_constexpr(T&&)` +* `is_constexpr()` +* `is_overloaded(T&&)` +* `is_overloaded()` +* `has_varargs(T&&)` +* `has_varargs()` +* `arity(T&&)` +* `arity()` +* `min_arity(T&&)` +* `min_arity()` +* `max_arity(T&&)` +* `max_arity()` +* `is_unqualified(T&&)` +* `is_unqualified()` +* `is_const_qualified(T&&)` +* `is_const_qualified()` +* `is_volatile_qualified(T&&)` +* `is_volatile_qualified()` +* `is_cv_qualified(T&&)` +* `is_cv_qualified()` +* `is_reference_qualified(T&&)` +* `is_reference_qualified()` +* `is_lvalue_reference_qualified(T&&)` +* `is_lvalue_reference_qualified()` +* `is_rvalue_reference_qualified(T&&)` +* `is_rvalue_reference_qualified()` + +[*Template aliases] + +* `args` +* `arg_at` +* `signature` +* `qualified_signature` +* `common_signature` +* `result_of` +* `remove_const_qualifier` +* `remove_volatile_qualifier` +* `remove_cv_qualifiers` +* `remove_reference_qualifiers` +* `remove_varargs` +* `add_const_qualifier` +* `add_volatile_qualifier` +* `add_cv_qualifiers` +* `add_lvalue_qualifier` +* `add_rvalue_qualifier` +* `add_varargs` + +[*Other] + +* `bind_expr(T, Args...)` + +[endsect] + +[section:tuto Overview] + +These are the + +To start using CallableTraits, include the header file: + + #include + +[endsect] \ No newline at end of file diff --git a/include/callable_traits/detail/function_object.hpp b/include/callable_traits/detail/function_object.hpp index 341f247..505672f 100644 --- a/include/callable_traits/detail/function_object.hpp +++ b/include/callable_traits/detail/function_object.hpp @@ -56,12 +56,18 @@ namespace callable_traits { template struct function_object - : public std::conditional< + : std::conditional< has_normal_call_operator::value, pmf::operator())>, ambiguous_function_object >::type { + using base = typename std::conditional< + has_normal_call_operator::value, + pmf::operator())>, + ambiguous_function_object + >::type; + using type = typename General::original_type; using general_type = typename General::type; diff --git a/include/callable_traits/detail/pmf.hpp b/include/callable_traits/detail/pmf.hpp index 79c44c0..a182e27 100644 --- a/include/callable_traits/detail/pmf.hpp +++ b/include/callable_traits/detail/pmf.hpp @@ -36,12 +36,17 @@ struct pmf using return_type = Return; \ using arg_types = std::tuple; \ using type = Return(T::*)(Args...) QUAL; \ + using invoke_type = typename std::conditional< \ + std::is_rvalue_reference::value, \ + T QUAL, \ + typename std::add_lvalue_reference::type \ + >::type; \ + \ using function_type = Return(Args...); \ using abominable_type = Return(Args...) QUAL; \ using remove_varargs = type; \ using add_varargs = Return(CALLABLE_TRAITS_VARARGS_CC T::*)(Args..., ...) QUAL; \ using class_type = T; \ - using invoke_type = T QUAL; \ \ using qualifiers = qualifier_traits; \ template \ @@ -87,12 +92,18 @@ struct pmf using return_type = Return; \ using arg_types = std::tuple; \ using type = Return(CALLABLE_TRAITS_VARARGS_CC T::*)(Args..., ...) QUAL; \ + \ + using invoke_type = typename std::conditional< \ + std::is_rvalue_reference::value, \ + T QUAL, \ + typename std::add_lvalue_reference::type \ + >::type; \ + \ using function_type = Return(Args..., ...); \ using abominable_type = Return(Args..., ...) QUAL; \ using remove_varargs = Return(T::*)(Args...) QUAL; \ using add_varargs = type; \ using class_type = T; \ - using invoke_type = T QUAL; \ \ using qualifiers = qualifier_traits; \ \ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 0000000..dcd0342 --- /dev/null +++ b/test/Jamfile.v2 @@ -0,0 +1,42 @@ +# Copyright Louis Dionne 2013-2016 +# Modified Work Copyright Barrett Adair 2016 +# 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 ; +import regex ; + +project callable_traits : + requirements + ../include +; + +rule callable_traits-all-tests { + local toolset = + clang:"-std=c++1y -pedantic -Wall -Wextra" + darwin:"-std=c++1y -pedantic -Wall -Wextra" + ; + + local result ; + + local sources = [ glob-tree *.cpp ] ; + for local source in $(sources) + { + local target = [ regex.replace $(source) "\.cpp" "" ] ; + target = [ regex.replace $(target) "/" "." ] ; + result += [ run $(source) : : : $(toolset) : test.$(target) ] ; + } + + return $(result) ; +} + +test-suite callable_traits : [ callable_traits-all-tests ] ; + +# Satisfy the Boost library requirements +test-suite minimal : callable_traits ; +test-suite full : callable_traits ; +test-suite extra : callable_traits ; + +explicit callable_traits ; +explicit minimal ; +explicit extra ; \ No newline at end of file