nvp.hpp 1000 B

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