Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

Class template value_ref

boost::log::value_ref — Reference wrapper for a stored attribute value.

Synopsis

// In header: <boost/log/utility/value_ref.hpp>

template<typename T, typename TagT> 
class value_ref {
public:
  // construct/copy/destruct
  value_ref() = default;
  value_ref(value_ref const &) = default;
  template<typename U> 
    explicit value_ref(U const &, 
                       typename enable_if< typename base_type::template is_compatible< U >, int >::type = 0);

  // public member functions
  explicit operator bool() const;
  bool operator!() const;
  bool empty() const;
  void swap(value_ref &);
};

Description

The value_ref class template provides access to the stored attribute value. It is not a traditional reference wrapper since it may be empty (i.e. refer to no value at all) and it can also refer to values of different types. Therefore its interface and behavior combines features of Boost.Ref, Boost.Optional and Boost.Variant, depending on the use case.

The template parameter T can be a single type or an MPL sequence of possible types being referred. The reference wrapper will act as either an optional reference or an optional variant of references to the specified types. In any case, the referred values will not be modifiable (i.e. value_ref always models a const reference).

Template parameter TagT is optional. It can be used for customizing the operations on this reference wrapper, such as putting the referred value to log.

value_ref public construct/copy/destruct

  1. value_ref() = default;

    Default constructor. Creates a reference wrapper that does not refer to a value.

  2. value_ref(value_ref const & that) = default;

    Copy constructor.

  3. template<typename U> 
      explicit value_ref(U const & val, 
                         typename enable_if< typename base_type::template is_compatible< U >, int >::type = 0);

    Initializing constructor. Creates a reference wrapper that refers to the specified value.

value_ref public member functions

  1. explicit operator bool() const;

    The operator verifies if the wrapper refers to a value.

  2. bool operator!() const;

    The operator verifies if the wrapper does not refer to a value.

  3. bool empty() const;

    Returns:

    true if the wrapper does not refer to a value.

  4. void swap(value_ref & that);

    Swaps two reference wrappers


PrevUpHomeNext