mirror of
https://github.com/boostorg/core.git
synced 2026-04-28 18:02:06 +02:00
Update NVP implementation, tests, docs
This commit is contained in:
@@ -8,44 +8,6 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#include <boost/core/nvp.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
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<int> p("name", v);
|
||||
saver s(0);
|
||||
p.serialize(s, unsigned());
|
||||
BOOST_TEST_EQ(s.get(), 1);
|
||||
}
|
||||
|
||||
void test_deserialize()
|
||||
{
|
||||
int v = 1;
|
||||
boost::nvp<int> 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<int>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::is_nvp<boost::nvp<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::is_nvp<const boost::nvp<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::is_nvp<volatile boost::nvp<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::is_nvp<const volatile boost::nvp<int> >));
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user