diff --git a/.travis.yml b/.travis.yml index 16f2043..b176281 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,9 +59,9 @@ script: - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/count_fields_on_long_longs.cpp && valgrind ./a.out && rm ./a.out - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/count_fields_on_shorts.cpp && valgrind ./a.out && rm ./a.out - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/count_fields_on_void_ptrs.cpp && valgrind ./a.out && rm ./a.out - - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/define_functions_for.cpp && valgrind ./a.out && rm ./a.out - - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/global_pod_ops.cpp && valgrind ./a.out && rm ./a.out + - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/flat_functions_for.cpp && valgrind ./a.out && rm ./a.out + - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/global_flat_ops.cpp && valgrind ./a.out && rm ./a.out - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/minimal.cpp && valgrind ./a.out && rm ./a.out - - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/pod_ops.cpp && valgrind ./a.out && rm ./a.out + - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/flat_ops.cpp && valgrind ./a.out && rm ./a.out - $TOOLSET -std=$CXX_STANDARD --coverage $INCLUDES test/std_interactions.cpp && valgrind ./a.out && rm ./a.out diff --git a/doc/pfr.qbk b/doc/pfr.qbk index 5e1f6a9..018bfc5 100644 --- a/doc/pfr.qbk +++ b/doc/pfr.qbk @@ -50,31 +50,31 @@ Boost.POD Flat Reflection (Boost.PFR) adds following out-of-the-box functionalit There are three ways to start using Boost.PFR hashing, comparison and streaming operators for type `T` in your code. Each method has it's own drawbacks and suits own cases. -[table:pod_ops_comp Different approaches for operators +[table:flat_ops_comp Different approaches for operators [[ Approach ] [ Defines operators in global namespace ] [ Defined operators could be found by ADL ] [ Works for local types ] [ Usable localy, without affecting code from other scopes ] [ Ignores implicit conversion operators ] [ Respects user defined operators ] ] - [[ [headerref boost/pfr/pod_ops.hpp] ] [ no ] [ no ] [ yes ] [ yes ] [ no ] [ yes ] ] - [[ [headerref boost/pfr/define_functions_for.hpp] ] [ yes if T is in it ] [ yes ] [ no ] [ no, but could be limited to translation unit ] [ yes for T ] [ no (compile time error) ] ] - [[ [headerref boost/pfr/global_pod_ops.hpp] ] [ yes ] [ yes ] [ yes ] [ no, but could be limited to translation unit ] [ yes all ] [ yes ] ] + [[ [headerref boost/pfr/flat_ops.hpp] ] [ no ] [ no ] [ yes ] [ yes ] [ no ] [ yes ] ] + [[ [headerref boost/pfr/flat_functions_for.hpp] ] [ yes if T is in it ] [ yes ] [ no ] [ no, but could be limited to translation unit ] [ yes for T ] [ no (compile time error) ] ] + [[ [headerref boost/pfr/global_flat_ops.hpp] ] [ yes ] [ yes ] [ yes ] [ no, but could be limited to translation unit ] [ yes all ] [ yes ] ] ] More detailed description: -[*1) [headerref boost/pfr/pod_ops.hpp] approach] +[*1) [headerref boost/pfr/flat_ops.hpp] approach] This method is good if you're writing generic algorithms and need to use operators from Boost.PFR only if there's no operators defined for the type: ``` -#include +#include template struct uniform_comparator_less { bool operator()(const T& lhs, const T& rhs) const noexcept { - using namespace pod_ops; // Enables Boost.PFR operators usage in this scope. + using namespace flat_ops; // Enables Boost.PFR operators usage in this scope. return lhs < rhs; // If T has operator< or conversion operator then will use it, otherwise will use boost::pfr::flat_less. } }; @@ -83,55 +83,55 @@ This method's effects are local to the function. It works even for local types, However *Argument Dependant Lookup* does not work with it: ``` -#include +#include template struct uniform_comparator_less { bool operator()(const T& lhs, const T& rhs) const noexcept { - using namespace pod_ops; + using namespace flat_ops; return std::less{}(lhs, rhs); // Compile time error if T has neither operator< nor conversion operator to comparable type. } }; ``` -[*2) [headerref boost/pfr/define_functions_for.hpp] approach] +[*2) [headerref boost/pfr/flat_functions_for.hpp] approach] This method is good if you're writing POD structure and wish to define operators for that structure. ``` -#include +#include struct pair_like { int first; short second; }; -BOOST_PFR_DEFINE_FUNCTIONS_FOR(pair_like) // Defines operators +BOOST_PFR_FLAT_FUNCTIONS_FOR(pair_like) // Defines operators // ... assert(pair_like{1, 2} < pair_like{1, 3}); ``` -Argument Dependant Lookup works well, `std::less` will find the operators for `struct pair_like`. [macroref BOOST_PFR_DEFINE_FUNCTIONS_FOR BOOST_PFR_DEFINE_FUNCTIONS_FOR(T)] +Argument Dependant Lookup works well, `std::less` will find the operators for `struct pair_like`. [macroref BOOST_PFR_FLAT_FUNCTIONS_FOR BOOST_PFR_FLAT_FUNCTIONS_FOR(T)] can not be used for local types, it must be called only once in namespace of `T`. It does not respect conversion operators of `T`, so for example the following code will output different values: ``` -#include +#include struct empty { operator std::string() { return "empty{}"; } }; // Uncomment to get different output: -// BOOST_PFR_DEFINE_FUNCTIONS_FOR(empty) +// BOOST_PFR_FLAT_FUNCTIONS_FOR(empty) // ... -std::cout << empty{}; // Outputs `empty{}` if BOOST_PFR_DEFINE_FUNCTIONS_FOR(empty) is commented out, '{}' otherwise. +std::cout << empty{}; // Outputs `empty{}` if BOOST_PFR_FLAT_FUNCTIONS_FOR(empty) is commented out, '{}' otherwise. ``` -[*3) [headerref boost/pfr/global_pod_ops.hpp] approach] +[*3) [headerref boost/pfr/global_flat_ops.hpp] approach] This approach is for those, who wish to have comparisong/streaming/hashing for all their types. ``` -#include +#include struct pair_like { int first; diff --git a/include/boost/pfr.hpp b/include/boost/pfr.hpp index 9afd13d..11a4ba5 100644 --- a/include/boost/pfr.hpp +++ b/include/boost/pfr.hpp @@ -6,7 +6,7 @@ #pragma once /// \file boost/pfr.hpp -/// Includes all the Boost.PFR headers, except \xmlonlyboost/pfr/global_flat_ops.hpp\endxmlonly +/// Includes all the Boost.PFR headers, except \xmlonlyboost/pfr/global_flat_ops.hpp\endxmlonly #include #include diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index 0003ae5..3425d6b 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -846,7 +846,7 @@ constexpr std::size_t tuple_size_v = tuple_size::value; /// assert(flat_get<0>(t) == 10); /// \endcode template -auto flat_make_tuple(const T& val) noexcept { +auto flat_structure_to_tuple(const T& val) noexcept { typedef detail::as_flat_tuple_t internal_tuple_t; return detail::make_stdtuple_from_seqtuple( @@ -864,11 +864,11 @@ auto flat_make_tuple(const T& val) noexcept { /// \code /// struct my_struct { int i, short s; }; /// my_struct s; -/// flat_tie(s) = std::tuple{10, 11}; +/// flat_structure_tie(s) = std::tuple{10, 11}; /// assert(s.s == 11); /// \endcode template -auto flat_tie(T& val /* @cond */, std::enable_if_t< std::is_trivially_assignable::value>* = 0 /* @endcond */) noexcept { +auto flat_structure_tie(T& val /* @cond */, std::enable_if_t< std::is_trivially_assignable::value>* = 0 /* @endcond */) noexcept { typedef detail::as_flat_tuple_t internal_tuple_t; return detail::tie_sequence_tuple_impl( diff --git a/include/boost/pfr/core17.hpp b/include/boost/pfr/core17.hpp index 1fe44ec..c90f877 100644 --- a/include/boost/pfr/core17.hpp +++ b/include/boost/pfr/core17.hpp @@ -89,7 +89,7 @@ using tuple_element_t = typename tuple_element::type; /// assert(get<0>(t) == 10); /// \endcode template -constexpr auto make_tuple(const T& val) noexcept { // TODO: Bad name :( +constexpr auto structure_to_tuple(const T& val) noexcept { typedef detail::as_tuple_t internal_tuple_t; return detail::make_stdtuple_from_seqtuple( @@ -111,7 +111,7 @@ constexpr auto make_tuple(const T& val) noexcept { // TODO: Bad /// assert(s.s == 11); /// \endcode template -constexpr auto tie(T& val) noexcept { // TODO: Bad name :( +constexpr auto structure_tie(T& val) noexcept { typedef detail::as_tuple_t internal_tuple_t; return detail::tie_sequence_tuple_impl( diff --git a/include/boost/pfr/flat_functions_for.hpp b/include/boost/pfr/flat_functions_for.hpp index 6207409..733b6f0 100644 --- a/include/boost/pfr/flat_functions_for.hpp +++ b/include/boost/pfr/flat_functions_for.hpp @@ -11,17 +11,17 @@ #include -/// \def BOOST_PFR_DEFINE_FUNCTIONS_FOR(T) +/// \def BOOST_PFR_FLAT_FUNCTIONS_FOR(T) /// Defines comparison operators and stream operators for T. /// If POD is comparable or streamable using it's own operator (but not it's conversion operator), then the original operator is used. /// /// \b Example: /// \code -/// #include +/// #include /// struct comparable_struct { // No operators defined for that structure /// int i; short s; char data[7]; bool bl; int a,b,c,d,e,f; /// }; -/// BOOST_PFR_DEFINE_FUNCTIONS_FOR(comparable_struct) +/// BOOST_PFR_FLAT_FUNCTIONS_FOR(comparable_struct) /// // ... /// /// comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; @@ -51,7 +51,7 @@ /// std::size_t hash_value(const T& value) noexcept; /// \endcode -#define BOOST_PFR_DEFINE_FUNCTIONS_FOR(T) \ +#define BOOST_PFR_FLAT_FUNCTIONS_FOR(T) \ static inline bool operator==(const T& lhs, const T& rhs) noexcept { return ::boost::pfr::flat_equal_to{}(lhs, rhs); } \ static inline bool operator!=(const T& lhs, const T& rhs) noexcept { return ::boost::pfr::flat_not_equal{}(lhs, rhs); } \ static inline bool operator< (const T& lhs, const T& rhs) noexcept { return ::boost::pfr::flat_less{}(lhs, rhs); } \ diff --git a/include/boost/pfr/flat_ops.hpp b/include/boost/pfr/flat_ops.hpp index 387f294..1124357 100644 --- a/include/boost/pfr/flat_ops.hpp +++ b/include/boost/pfr/flat_ops.hpp @@ -11,21 +11,21 @@ #include -/// \file boost/pfr/pod_ops.hpp +/// \file boost/pfr/flat_ops.hpp /// Contains comparison operators and stream operators for any POD types that do not have their own operators. /// If POD is comparable or streamable using it's own operator or it's conversion operator, then the original operator is used. /// -/// Just write \b using \b namespace \b pod_ops; and operators will be available in scope. +/// Just write \b using \b namespace \b flat_ops; and operators will be available in scope. /// /// \b Example: /// \code -/// #include +/// #include /// struct comparable_struct { // No operators defined for that structure /// int i; short s; char data[7]; bool bl; int a,b,c,d,e,f; /// }; /// // ... /// -/// using namespace pod_ops; +/// using namespace flat_ops; /// /// comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; /// comparable_struct s2 {0, 1, "Hello", false, 6,7,8,9,10,11111}; @@ -91,7 +91,7 @@ namespace detail { >::type; } // namespace detail -namespace pod_ops { +namespace flat_ops { #ifdef BOOST_PFR_DOXYGEN_INVOKED template bool operator==(const T& lhs, const T& rhs) noexcept; template bool operator!=(const T& lhs, const T& rhs) noexcept; @@ -157,6 +157,6 @@ namespace pod_ops { } #endif -} // namespace pod_ops +} // namespace flat_ops }} // namespace boost::pfr diff --git a/include/boost/pfr/global_flat_ops.hpp b/include/boost/pfr/global_flat_ops.hpp index 38bc539..3a8131e 100644 --- a/include/boost/pfr/global_flat_ops.hpp +++ b/include/boost/pfr/global_flat_ops.hpp @@ -11,13 +11,13 @@ #include -/// \file boost/pfr/global_pod_ops.hpp +/// \file boost/pfr/global_flat_ops.hpp /// Contains comparison operators and stream operators for any POD types that do not have their own operators. /// If POD is comparable or streamable using it's own operator (but not it's conversion operator), then the original operator is used. /// /// \b Example: /// \code -/// #include +/// #include /// struct comparable_struct { // No operators defined for that structure /// int i; short s; char data[7]; bool bl; int a,b,c,d,e,f; /// }; diff --git a/misc/generate_single.sh b/misc/generate_single.sh index 53dd860..f87105a 100755 --- a/misc/generate_single.sh +++ b/misc/generate_single.sh @@ -1,4 +1,4 @@ cat ../include/boost/pfr/core.hpp sed -e '1,/boost\/pfr/d' ../include/boost/pfr/functors.hpp -sed -e '1,/boost\/pfr/d' ../include/boost/pfr/define_functions_for.hpp -sed -e '1,/boost\/pfr/d' ../include/boost/pfr/pod_ops.hpp +sed -e '1,/boost\/pfr/d' ../include/boost/pfr/flat_functions_for.hpp +sed -e '1,/boost\/pfr/d' ../include/boost/pfr/flat_ops.hpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 70e5ce1..16598f1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -15,9 +15,9 @@ test-suite pfr # [ run count_fields_on_shorts.cpp ] [ run count_fields_on_void_ptrs.cpp ] [ run std_interactions.cpp ] - [ run define_functions_for.cpp ] - [ run pod_ops.cpp ] - [ run global_pod_ops.cpp ] + [ run flat_functions_for.cpp ] + [ run flat_ops.cpp ] + [ run global_flat_ops.cpp ] [ compile-fail non_aggregate1.cpp ] [ compile-fail non_aggregate2.cpp ] [ compile-fail bitfields.cpp ] diff --git a/test/core.cpp b/test/core.cpp index 903cae6..b0cf322 100644 --- a/test/core.cpp +++ b/test/core.cpp @@ -140,7 +140,7 @@ void test_with_enums() { }; struct my_struct { my_enum e; int i; short s; }; my_struct s {my_enum::VALUE1, 10, 11}; - std::tuple t = flat_make_tuple(s); + std::tuple t = flat_structure_to_tuple(s); BOOST_TEST_EQ(std::get<0>(t), 17u); BOOST_TEST_EQ(std::get<1>(t), 10); BOOST_TEST_EQ(std::get<2>(t), 11); @@ -150,10 +150,10 @@ void test_with_enums() { flat_get<2>(s) = 111; BOOST_TEST_EQ(flat_get<2>(s), 111); - BOOST_TEST(flat_tie(s) == flat_tie(s)); - BOOST_TEST(flat_tie(s) == flat_make_tuple(s)); - BOOST_TEST(flat_tie(s) != t); - flat_tie(s) = t; + BOOST_TEST(flat_structure_tie(s) == flat_structure_tie(s)); + BOOST_TEST(flat_structure_tie(s) == flat_structure_to_tuple(s)); + BOOST_TEST(flat_structure_tie(s) != t); + flat_structure_tie(s) = t; BOOST_TEST_EQ(flat_get<0>(s), 17u); BOOST_TEST_EQ(flat_get<1>(s), 10); BOOST_TEST_EQ(flat_get<2>(s), 11); @@ -189,7 +189,7 @@ void test_comparable_struct() { struct comparable_struct { int i; short s; char data[50]; bool bl; int a,b,c,d,e,f; }; - using namespace pod_ops; + using namespace flat_ops; comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; comparable_struct s2 = s1; @@ -220,7 +220,7 @@ void test_comparable_struct() { void test_empty_struct() { struct empty {}; - using namespace pod_ops; + using namespace flat_ops; std::cout << empty{} << std::endl; @@ -229,7 +229,7 @@ void test_empty_struct() { void test_pods_with_int_operators() { - using namespace pod_ops; + using namespace flat_ops; std::stringstream ss; ss << std::is_pod{}; @@ -242,7 +242,7 @@ void test_pods_with_int_operators() { void test_struct_with_single_field() { struct f1 { int i; }; - using namespace pod_ops; + using namespace flat_ops; std::stringstream ss; ss << f1{ 777 }; diff --git a/test/define_functions_for.cpp b/test/flat_functions_for.cpp similarity index 91% rename from test/define_functions_for.cpp rename to test/flat_functions_for.cpp index 4e29c2a..5938df8 100644 --- a/test/define_functions_for.cpp +++ b/test/flat_functions_for.cpp @@ -3,7 +3,7 @@ // 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 #include #include @@ -28,7 +28,7 @@ struct comparable_struct { int i; short s; char data[50]; bool bl; int a,b,c,d,e,f; }; -BOOST_PFR_DEFINE_FUNCTIONS_FOR(comparable_struct) +BOOST_PFR_FLAT_FUNCTIONS_FOR(comparable_struct) void test_comparable_struct() { comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; @@ -59,7 +59,7 @@ void test_comparable_struct() { } struct empty { operator std::string() { return "empty{}"; } }; -BOOST_PFR_DEFINE_FUNCTIONS_FOR(empty) +BOOST_PFR_FLAT_FUNCTIONS_FOR(empty) void test_empty_struct() { BOOST_TEST_EQ(empty{}, empty{}); @@ -67,7 +67,7 @@ void test_empty_struct() { namespace foo { struct testing { bool b1, b2; int i; }; - BOOST_PFR_DEFINE_FUNCTIONS_FOR(testing); + BOOST_PFR_FLAT_FUNCTIONS_FOR(testing); } template @@ -93,7 +93,7 @@ void test_implicit_conversions() { ss.str(""); ss << empty{}; - BOOST_TEST_EQ(ss.str(), "{}"); // Breaks implicit conversion for types marked with BOOST_PFR_DEFINE_FUNCTIONS_FOR + BOOST_TEST_EQ(ss.str(), "{}"); // Breaks implicit conversion for types marked with BOOST_PFR_FLAT_FUNCTIONS_FOR } int main() { diff --git a/test/pod_ops.cpp b/test/flat_ops.cpp similarity index 95% rename from test/pod_ops.cpp rename to test/flat_ops.cpp index daed1f0..305848c 100644 --- a/test/pod_ops.cpp +++ b/test/flat_ops.cpp @@ -15,7 +15,7 @@ template void test_comparable_struct() { - using namespace boost::pfr::pod_ops; + using namespace boost::pfr::flat_ops; T s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; T s2 = s1; @@ -46,7 +46,7 @@ void test_comparable_struct() { void test_empty_struct() { struct empty {}; - using namespace boost::pfr::pod_ops; + using namespace boost::pfr::flat_ops; std::cout << empty{}; BOOST_TEST(empty{} == empty{}); diff --git a/test/global_pod_ops.cpp b/test/global_flat_ops.cpp similarity index 100% rename from test/global_pod_ops.cpp rename to test/global_flat_ops.cpp