nvp.qbk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. [section:nvp nvp]
  8. [section Overview]
  9. The header <boost/core/nvp.hpp> provides the class template `boost::nvp` that
  10. pairs a name (`const char*`) with the address of a value (`T*`). It is the new
  11. implementation of the NVP type previously provided by the Boost Serialization
  12. library. This type now lives in the Core library so that other Boost libraries
  13. can support named value serialization without taking a dependency on the
  14. Serialization library.
  15. [endsect]
  16. [section Examples]
  17. The following snippet shows use in a member serialize function:
  18. ```
  19. template<class A>
  20. void serialize(A& archive, unsigned)
  21. {
  22. archive & boost::make_nvp("x", x_) & boost::make_nvp("y", y_);
  23. }
  24. ```
  25. [endsect]
  26. [section Reference]
  27. ```
  28. namespace boost {
  29. template<class T>
  30. class nvp {
  31. public:
  32. nvp(const char* name, T& value) noexcept;
  33. const char* name() const noexcept;
  34. T& value() const noexcept;
  35. const T& const_value() const noexcept;
  36. };
  37. template<class T>
  38. const nvp<T> make_nvp(const char* name, T& value) noexcept;
  39. } /* boost */
  40. #define BOOST_NVP(object) ``['see below]``
  41. ```
  42. [section Constructors]
  43. [variablelist
  44. [[`nvp(const char* name, T& value) noexcept;`]
  45. [Initializes the stored name pointer with `name` and the value pointer with
  46. `addressof(value)`.]]]
  47. [endsect]
  48. [section Members]
  49. [variablelist
  50. [[`const char* name() const noexcept;`]
  51. [Returns a pointer to the name.]]
  52. [[`T& value() const noexcept;`]
  53. [Returns a reference to the value.]]
  54. [[`const T& const_value() const noexcept;`]
  55. [Returns a reference to the value.]]]
  56. [endsect]
  57. [section Functions]
  58. [variablelist
  59. [[`template<class T> const nvp<T> make_nvp(const char* name, T& value)
  60. noexcept;`]
  61. [Returns `nvp<T>(name, value)`.]]]
  62. [endsect]
  63. [section Macros]
  64. [variablelist
  65. [[`#define BOOST_NVP(object) see below`]
  66. [Expands to `boost::make_nvp(BOOST_STRINGIZE(object), object)`.]]]
  67. [endsect]
  68. [endsect]
  69. [section History]
  70. Robert Ramey originally implemented NVP in the Serialization library. Glen
  71. Fernandes implemented this new (but compatible) version in the Core library.
  72. [endsect]
  73. [endsect]