forked from boostorg/core
Add BOOST_NVP convenience macro
This commit is contained in:
10
doc/nvp.qbk
10
doc/nvp.qbk
@ -54,6 +54,8 @@ template<class T>
|
||||
const nvp<T> make_nvp(const char* name, T& value) noexcept;
|
||||
|
||||
} /* boost */
|
||||
|
||||
#define BOOST_NVP(object) ``['see below]``
|
||||
```
|
||||
|
||||
[section Constructors]
|
||||
@ -86,6 +88,14 @@ noexcept;`]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Macros]
|
||||
|
||||
[variablelist
|
||||
[[`#define BOOST_NVP(object) see below`]
|
||||
[Expands to `boost::make_nvp(BOOST_STRINGIZE(object), object)`.]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Acknowledgments]
|
||||
|
@ -46,4 +46,6 @@ make_nvp(const char* n, T& v) BOOST_NOEXCEPT
|
||||
|
||||
} /* boost */
|
||||
|
||||
#define BOOST_NVP(v) boost::make_nvp(BOOST_STRINGIZE(v), v)
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/nvp.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
void test()
|
||||
{
|
||||
@ -28,9 +28,19 @@ void test_factory()
|
||||
BOOST_TEST_EQ(&p.value(), &v);
|
||||
}
|
||||
|
||||
void test_macro()
|
||||
{
|
||||
int v = 1;
|
||||
boost::nvp<int> p = BOOST_NVP(v);
|
||||
BOOST_TEST_CSTR_EQ(p.name(), "v");
|
||||
BOOST_TEST_EQ(p.value(), 1);
|
||||
BOOST_TEST_EQ(&p.value(), &v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
test_factory();
|
||||
test_macro();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user