From edcd9e2cf55c5b1289fccfc183be5804b7f95e72 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 26 Aug 2018 10:07:19 -0400 Subject: [PATCH] Add documentation for empty_value --- doc/core.qbk | 1 + doc/empty_value.qbk | 123 +++++++++++++++++++++++++++++ include/boost/core/empty_value.hpp | 4 +- 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 doc/empty_value.qbk diff --git a/doc/core.qbk b/doc/core.qbk index 0eaaf67..3583bc6 100644 --- a/doc/core.qbk +++ b/doc/core.qbk @@ -41,6 +41,7 @@ criteria for inclusion is that the utility component be: [include addressof.qbk] [include checked_delete.qbk] [include demangle.qbk] +[include empty_value.qbk] [include enable_if.qbk] [include exchange.qbk] [include explicit_operator_bool.qbk] diff --git a/doc/empty_value.qbk b/doc/empty_value.qbk new file mode 100644 index 0000000..cb6cb12 --- /dev/null +++ b/doc/empty_value.qbk @@ -0,0 +1,123 @@ +[/ +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +] + +[section:empty_value empty_value] + +[simplesect Authors] + +* Glen Fernandes + +[endsimplesect] + +[section Overview] + +The header provides the class template +`boost::empty_value` for library authors to conveniently leverage the Empty +Base Optimization to store objects of potentially empty types. + +[endsect] + +[section Examples] + +The following example shows `boost::empty_value` used to create a type that +stores a pointer, comparer, and allocator, where the comparer and allocator +could be empty types. + +``` +template +class storage + : empty_value + , empty_value { +public: + storage() + : empty_value(empty_init_t()) + , empty_value(empty_init_t()) + , ptr_() { } + + storage(const Compare& c, const Allocator& a) + : empty_value(empty_init_t(), c) + , empty_value(empty_init_t(), a) + , ptr_() { } + + const Ptr& pointer() const + { return ptr_; } + + Ptr& pointer() + { return ptr_; } + + const Compare& compare() const + { return empty_value::get(); } + + Compare& compare() + { return empty_value::get(); } + + const Allocator& allocator() const + { return empty_value::get(); } + + Allocator& allocator() + { return empty_value::get(); } + +private: + Ptr ptr_; +}; +``` + +[endsect] + +[section Reference] + +``` +namespace boost { + +struct empty_init_t { }; + +template +class empty_value { +public: + empty_value() = default; + + template + explicit empty_value(empty_init_t, Args&&... args); + + const T& get() const; + + T& get(); +}; + +} /* boost */ +``` + +[section Template parameters] + +[variablelist +[[`T`][The type of value to store]] +[[`Index`][Optional: Specify to create a distinct base type]] +[[`Empty`][Optional: Specify to force inheritance from type]]] + +[endsect] + +[section Constructors] + +[variablelist +[[`empty_value() = default;`][Default initialize the value]] +[[`template empty_value(empty_init_t, Args&&... args);`] +[Initialize the value with `std::forward(args)...`]]] + +[endsect] + +[section Member functions] + +[variablelist +[[`const T& get() const;`][Returns the value]] +[[`T& get();`][Returns the value]]] + +[endsect] + +[endsect] + +[endsect] diff --git a/include/boost/core/empty_value.hpp b/include/boost/core/empty_value.hpp index b67d42c..a10e1bf 100644 --- a/include/boost/core/empty_value.hpp +++ b/include/boost/core/empty_value.hpp @@ -55,7 +55,7 @@ public: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template - empty_value(empty_init_t, Args&&... args) + explicit empty_value(empty_init_t, Args&&... args) : value_(std::forward(args)...) { } #else template @@ -97,7 +97,7 @@ public: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template - empty_value(empty_init_t, Args&&... args) + explicit empty_value(empty_init_t, Args&&... args) : T(std::forward(args)...) { } #else template