forked from boostorg/core
Update NVP implementation, tests, docs
This commit is contained in:
@@ -12,28 +12,6 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template<bool V>
|
||||
struct nvp_bool {
|
||||
typedef bool value_type;
|
||||
typedef nvp_bool type;
|
||||
|
||||
BOOST_STATIC_CONSTEXPR bool value = V;
|
||||
|
||||
BOOST_CONSTEXPR operator bool() const BOOST_NOEXCEPT {
|
||||
return V;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR bool operator()() const BOOST_NOEXCEPT {
|
||||
return V;
|
||||
}
|
||||
};
|
||||
|
||||
template<bool V>
|
||||
BOOST_CONSTEXPR_OR_CONST bool nvp_bool<V>::value;
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class T>
|
||||
class nvp {
|
||||
@@ -54,46 +32,11 @@ public:
|
||||
return *v_;
|
||||
}
|
||||
|
||||
template<class A>
|
||||
void serialize(A& a, unsigned) {
|
||||
archive(a, detail::nvp_bool<A::is_saving::value>());
|
||||
}
|
||||
|
||||
private:
|
||||
template<class A>
|
||||
void archive(A& a, detail::nvp_bool<true>) const {
|
||||
a.operator<<(*v_);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
void archive(A& a, detail::nvp_bool<false>) {
|
||||
a.operator>>(*v_);
|
||||
}
|
||||
|
||||
const char* n_;
|
||||
T* v_;
|
||||
};
|
||||
|
||||
template<class>
|
||||
struct is_nvp
|
||||
: detail::nvp_bool<false> { };
|
||||
|
||||
template<class T>
|
||||
struct is_nvp<nvp<T> >
|
||||
: detail::nvp_bool<true> { };
|
||||
|
||||
template<class T>
|
||||
struct is_nvp<const nvp<T> >
|
||||
: detail::nvp_bool<true> { };
|
||||
|
||||
template<class T>
|
||||
struct is_nvp<volatile nvp<T> >
|
||||
: detail::nvp_bool<true> { };
|
||||
|
||||
template<class T>
|
||||
struct is_nvp<const volatile nvp<T> >
|
||||
: detail::nvp_bool<true> { };
|
||||
|
||||
template<class T>
|
||||
inline const nvp<T>
|
||||
make_nvp(const char* n, T& v) BOOST_NOEXCEPT
|
||||
|
||||
Reference in New Issue
Block a user