mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-21 05:02:15 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89b1d45ff7 | ||
|
|
26867f47b7 | ||
|
|
b9166fd38e | ||
|
|
915bd9217c |
@@ -18,6 +18,7 @@
|
||||
#include <boost/pfr/detail/make_flat_tuple_of_references.hpp>
|
||||
#include <boost/pfr/detail/make_integer_sequence.hpp>
|
||||
#include <boost/pfr/detail/size_array.hpp>
|
||||
#include <boost/pfr/detail/size_t_.hpp>
|
||||
#include <boost/pfr/detail/rvalue_t.hpp>
|
||||
|
||||
#ifdef __clang__
|
||||
@@ -32,10 +33,7 @@ namespace boost { namespace pfr { namespace detail {
|
||||
|
||||
///////////////////// General utility stuff
|
||||
|
||||
template <std::size_t Index>
|
||||
using size_t_ = std::integral_constant<std::size_t, Index >;
|
||||
|
||||
template <class T> struct identity{
|
||||
template <class T> struct identity {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ struct ubiq_lref_constructor {
|
||||
///////////////////// Structure that can be converted to rvalue reference to anything
|
||||
struct ubiq_rref_constructor {
|
||||
std::size_t ignore;
|
||||
template <class Type> /*constexpr*/ operator Type&&() const noexcept {}; // Allows initialization of rvalue reference fields and move-only types
|
||||
template <class Type> /*constexpr*/ operator Type&&() const noexcept { // Allows initialization of rvalue reference fields and move-only types
|
||||
return detail::unsafe_declval<Type&&>();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,20 @@
|
||||
|
||||
namespace boost { namespace pfr { namespace detail {
|
||||
|
||||
// For returning non default constructible types. Never used at runtime! GCC's
|
||||
// std::declval may not be used in potentionally evaluated contexts, so it does not work here.
|
||||
template <class T> constexpr T unsafe_declval() noexcept {
|
||||
// This function serves as a link-time assert. If linker requires it, then
|
||||
// `unsafe_declval()` is used at runtime.
|
||||
void report_if_you_see_link_error_with_this_function() noexcept;
|
||||
|
||||
// For returning non default constructible types. Do NOT use at runtime!
|
||||
//
|
||||
// GCC's std::declval may not be used in potentionally evaluated contexts,
|
||||
// so we reinvent it.
|
||||
template <class T>
|
||||
constexpr T unsafe_declval() noexcept {
|
||||
report_if_you_see_link_error_with_this_function();
|
||||
|
||||
typename std::remove_reference<T>::type* ptr = 0;
|
||||
ptr += 42; // killing 'null pointer dereference' heuristics of static analysis tools
|
||||
ptr += 42; // suppresses 'null pointer dereference' warnings
|
||||
return static_cast<T>(*ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ void test_in_anon_ns() {
|
||||
BOOST_TEST_EQ(std::get<1>(v).data, 2);
|
||||
|
||||
#ifdef __cpp_lib_optional
|
||||
other_anon_with_optional opt{"test"};
|
||||
other_anon_with_optional opt{"test", {}, {}, {}};
|
||||
auto opt_val = boost::pfr::structure_tie(opt);
|
||||
BOOST_TEST_EQ(std::get<0>(opt_val), "test");
|
||||
#endif
|
||||
@@ -76,7 +76,7 @@ void test_in_non_non_ns() {
|
||||
BOOST_TEST_EQ(std::get<1>(v).data, 2);
|
||||
|
||||
#ifdef __cpp_lib_optional
|
||||
other_anon_with_optional opt{"test again"};
|
||||
other_anon_with_optional opt{"test again", {}, {}, {}};
|
||||
auto opt_val = boost::pfr::structure_tie(opt);
|
||||
BOOST_TEST_EQ(std::get<0>(opt_val), "test again");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user