| 1 | /* |
| 2 | Copyright 2019 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #ifndef BOOST_CORE_NVP_HPP |
| 9 | #define BOOST_CORE_NVP_HPP |
| 10 | |
| 11 | #include <boost/core/addressof.hpp> |
| 12 | #include <boost/config.hpp> |
| 13 | |
| 14 | namespace boost { |
| 15 | namespace serialization { |
| 16 | |
| 17 | template<class T> |
| 18 | class nvp { |
| 19 | public: |
| 20 | nvp(const char* n, T& v) BOOST_NOEXCEPT |
| 21 | : n_(n) |
| 22 | , v_(boost::addressof(v)) { } |
| 23 | |
| 24 | const char* name() const BOOST_NOEXCEPT { |
| 25 | return n_; |
| 26 | } |
| 27 | |
| 28 | T& value() const BOOST_NOEXCEPT { |
| 29 | return *v_; |
| 30 | } |
| 31 | |
| 32 | const T& const_value() const BOOST_NOEXCEPT { |
| 33 | return *v_; |
| 34 | } |
| 35 | |
| 36 | private: |
| 37 | const char* n_; |
| 38 | T* v_; |
| 39 | }; |
| 40 | |
| 41 | template<class T> |
| 42 | inline const nvp<T> |
| 43 | make_nvp(const char* n, T& v) BOOST_NOEXCEPT |
| 44 | { |
| 45 | return nvp<T>(n, v); |
| 46 | } |
| 47 | |
| 48 | } /* serialization */ |
| 49 | |
| 50 | using serialization::nvp; |
| 51 | using serialization::make_nvp; |
| 52 | |
| 53 | } /* boost */ |
| 54 | |
| 55 | #define BOOST_NVP(v) boost::make_nvp(BOOST_STRINGIZE(v), v) |
| 56 | |
| 57 | #endif |
| 58 | |