From 7cc1047ab749bcdc5999b63aa57cfefad05e1407 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 15 Sep 2019 21:12:09 -0400 Subject: [PATCH] Update NVP implementation, tests, docs --- doc/nvp.qbk | 20 +---------- include/boost/core/nvp.hpp | 57 -------------------------------- test/nvp_test.cpp | 68 -------------------------------------- 3 files changed, 1 insertion(+), 144 deletions(-) diff --git a/doc/nvp.qbk b/doc/nvp.qbk index 0e90e38..233b329 100644 --- a/doc/nvp.qbk +++ b/doc/nvp.qbk @@ -48,14 +48,8 @@ public: T& value() const noexcept; const T& const_value() const noexcept; - - template - void serialize(A& archive, unsigned); }; -template -struct is_nvp; - template const nvp make_nvp(const char* name, T& value) noexcept; @@ -79,19 +73,7 @@ const nvp make_nvp(const char* name, T& value) noexcept; [[`T& value() const noexcept;`] [Returns a reference to the value.]] [[`const T& const_value() const noexcept;`] -[Returns a reference to the value.]] -[[`template void serialize(A& archive, unsigned);`] -[Calls `archive.operator<<(const_value())` if `A::is_saving` is a true type, -otherwise `archive.operator>>(value())`.]]] - -[endsect] - -[section Traits] - -[variablelist -[[`template struct is_nvp;`] -[Provides static constant `value` equal to true if `T` is an NVP type, -otherwise false.]]] +[Returns a reference to the value.]]] [endsect] diff --git a/include/boost/core/nvp.hpp b/include/boost/core/nvp.hpp index a6c2bda..deab002 100644 --- a/include/boost/core/nvp.hpp +++ b/include/boost/core/nvp.hpp @@ -12,28 +12,6 @@ Distributed under the Boost Software License, Version 1.0. #include namespace boost { -namespace detail { - -template -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 -BOOST_CONSTEXPR_OR_CONST bool nvp_bool::value; - -} /* detail */ template class nvp { @@ -54,46 +32,11 @@ public: return *v_; } - template - void serialize(A& a, unsigned) { - archive(a, detail::nvp_bool()); - } - private: - template - void archive(A& a, detail::nvp_bool) const { - a.operator<<(*v_); - } - - template - void archive(A& a, detail::nvp_bool) { - a.operator>>(*v_); - } - const char* n_; T* v_; }; -template -struct is_nvp - : detail::nvp_bool { }; - -template -struct is_nvp > - : detail::nvp_bool { }; - -template -struct is_nvp > - : detail::nvp_bool { }; - -template -struct is_nvp > - : detail::nvp_bool { }; - -template -struct is_nvp > - : detail::nvp_bool { }; - template inline const nvp make_nvp(const char* n, T& v) BOOST_NOEXCEPT diff --git a/test/nvp_test.cpp b/test/nvp_test.cpp index b87f029..2e8316e 100644 --- a/test/nvp_test.cpp +++ b/test/nvp_test.cpp @@ -8,44 +8,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include -class saver { -public: - struct is_saving { - static const bool value = true; - }; - - explicit saver(int value) - : value_(value) { } - - int get() const { - return value_; - } - - void operator<<(int value) { - value_ = value; - } - -private: - int value_; -}; - -class loader { -public: - struct is_saving { - static const bool value = false; - }; - - explicit loader(int value) - : value_(value) { } - - void operator>>(int& value) { - value = value_; - } - -private: - int value_; -}; - void test() { const char* n = "name"; @@ -56,33 +18,6 @@ void test() BOOST_TEST_EQ(&p.value(), &v); } -void test_serialize() -{ - int v = 1; - boost::nvp p("name", v); - saver s(0); - p.serialize(s, unsigned()); - BOOST_TEST_EQ(s.get(), 1); -} - -void test_deserialize() -{ - int v = 1; - boost::nvp p("name", v); - loader l(5); - p.serialize(l, unsigned()); - BOOST_TEST_EQ(p.value(), 5); -} - -void test_trait() -{ - BOOST_TEST_TRAIT_FALSE((boost::is_nvp)); - BOOST_TEST_TRAIT_TRUE((boost::is_nvp >)); - BOOST_TEST_TRAIT_TRUE((boost::is_nvp >)); - BOOST_TEST_TRAIT_TRUE((boost::is_nvp >)); - BOOST_TEST_TRAIT_TRUE((boost::is_nvp >)); -} - void test_factory() { const char* n = "name"; @@ -96,9 +31,6 @@ void test_factory() int main() { test(); - test_serialize(); - test_deserialize(); - test_trait(); test_factory(); return boost::report_errors(); }