2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Move more files to better reflect their content and usability (pod_ -> flat_)

This commit is contained in:
Antony Polukhin
2016-07-18 23:54:07 +03:00
parent 494a9cf6ca
commit 9fbb780839
14 changed files with 60 additions and 60 deletions

View File

@@ -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

View File

@@ -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 <boost/pfr/pod_ops.hpp>
#include <boost/pfr/flat_ops.hpp>
template <class T>
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<T>.
}
};
@@ -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 <boost/pfr/pod_ops.hpp>
#include <boost/pfr/flat_ops.hpp>
template <class T>
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 <boost/pfr/define_functions_for.hpp>
#include <boost/pfr/flat_functions_for.hpp>
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 <boost/pfr/define_functions_for.hpp>
#include <boost/pfr/flat_functions_for.hpp>
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 <boost/pfr/global_pod_ops.hpp>
#include <boost/pfr/global_flat_ops.hpp>
struct pair_like {
int first;

View File

@@ -6,7 +6,7 @@
#pragma once
/// \file boost/pfr.hpp
/// Includes all the Boost.PFR headers, except \xmlonly<link linkend='header.boost.pfr.global_pod_ops_hpp'>boost/pfr/global_flat_ops.hpp</link>\endxmlonly
/// Includes all the Boost.PFR headers, except \xmlonly<link linkend='header.boost.pfr.global_flat_ops_hpp'>boost/pfr/global_flat_ops.hpp</link>\endxmlonly
#include <boost/pfr/core.hpp>
#include <boost/pfr/core17.hpp>

View File

@@ -846,7 +846,7 @@ constexpr std::size_t tuple_size_v = tuple_size<T>::value;
/// assert(flat_get<0>(t) == 10);
/// \endcode
template <class T>
auto flat_make_tuple(const T& val) noexcept {
auto flat_structure_to_tuple(const T& val) noexcept {
typedef detail::as_flat_tuple_t<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<int, short>{10, 11};
/// flat_structure_tie(s) = std::tuple<int, short>{10, 11};
/// assert(s.s == 11);
/// \endcode
template <class T>
auto flat_tie(T& val /* @cond */, std::enable_if_t< std::is_trivially_assignable<T, T>::value>* = 0 /* @endcond */) noexcept {
auto flat_structure_tie(T& val /* @cond */, std::enable_if_t< std::is_trivially_assignable<T, T>::value>* = 0 /* @endcond */) noexcept {
typedef detail::as_flat_tuple_t<T> internal_tuple_t;
return detail::tie_sequence_tuple_impl(

View File

@@ -89,7 +89,7 @@ using tuple_element_t = typename tuple_element<I, T>::type;
/// assert(get<0>(t) == 10);
/// \endcode
template <class T>
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<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 <class T>
constexpr auto tie(T& val) noexcept { // TODO: Bad name :(
constexpr auto structure_tie(T& val) noexcept {
typedef detail::as_tuple_t<T> internal_tuple_t;
return detail::tie_sequence_tuple_impl(

View File

@@ -11,17 +11,17 @@
#include <boost/pfr/functors.hpp>
/// \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 <boost/pfr/define_functions_for.hpp>
/// #include <boost/pfr/flat_functions_for.hpp>
/// 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<T>{}(lhs, rhs); } \
static inline bool operator!=(const T& lhs, const T& rhs) noexcept { return ::boost::pfr::flat_not_equal<T>{}(lhs, rhs); } \
static inline bool operator< (const T& lhs, const T& rhs) noexcept { return ::boost::pfr::flat_less<T>{}(lhs, rhs); } \

View File

@@ -11,21 +11,21 @@
#include <boost/pfr/functors.hpp>
/// \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 <boost/pfr/pod_ops.hpp>
/// #include <boost/pfr/flat_ops.hpp>
/// 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 <class T> bool operator==(const T& lhs, const T& rhs) noexcept;
template <class T> 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

View File

@@ -11,13 +11,13 @@
#include <boost/pfr/functors.hpp>
/// \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 <boost/pfr/global_pod_ops.hpp>
/// #include <boost/pfr/global_flat_ops.hpp>
/// 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;
/// };

View File

@@ -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

View File

@@ -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 ]

View File

@@ -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<unsigned, int, short> t = flat_make_tuple(s);
std::tuple<unsigned, int, short> 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<int>{};
@@ -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 };

View File

@@ -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 <boost/pfr/define_functions_for.hpp>
#include <boost/pfr/flat_functions_for.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
@@ -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 <class Comparator>
@@ -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() {

View File

@@ -15,7 +15,7 @@
template <class T>
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{});