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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class attribute

boost::log::attribute — A base class for an attribute value factory.


// In header: <boost/log/attributes/attribute.hpp>

class attribute {
  // member classes/structs/unions

  // A base class for an attribute value factory.

  struct impl : public boost::intrusive_ref_counter< impl > {
    // construct/copy/destruct

    // public member functions
    virtual attribute_value get_value() = 0;

    // public static functions
    static void * operator new(std::size_t);
    static void operator delete(void *, std::size_t) noexcept;
  // construct/copy/destruct
  attribute() = default;
  attribute(attribute const &) noexcept;
  attribute(attribute &&) noexcept;
  explicit attribute(intrusive_ptr< impl >) noexcept;
  attribute & operator=(attribute const &) noexcept;
  attribute & operator=(attribute &&) noexcept;

  // public member functions
  explicit operator bool() const noexcept;
  bool operator!() const noexcept;
  attribute_value get_value() const;
  void swap(attribute &) noexcept;

  // protected member functions
  impl * get_impl() const noexcept;
  void set_impl(intrusive_ptr< impl >) noexcept;

  // friend functions
  template<typename T> friend T attribute_cast(attribute const &);


Every attribute is represented with a factory that is basically an attribute value generator. The sole purpose of an attribute is to return an actual value when requested. A simplest attribute can always return the same value that it stores internally, but more complex ones can perform a considerable amount of work to return a value, and the returned values may differ each time requested.

A word about thread safety. An attribute should be prepared to be requested a value from multiple threads concurrently.

attribute public construct/copy/destruct

  1. attribute() = default;

    Default constructor. Creates an empty attribute value factory, which is not usable until set_impl is called.

  2. attribute(attribute const & that) noexcept;

    Copy constructor

  3. attribute(attribute && that) noexcept;

    Move constructor

  4. explicit attribute(intrusive_ptr< impl > p) noexcept;

    Initializing constructor



    Pointer to the implementation. Must not be NULL.

  5. attribute & operator=(attribute const & that) noexcept;

    Copy assignment

  6. attribute & operator=(attribute && that) noexcept;

    Move assignment

attribute public member functions

  1. explicit operator bool() const noexcept;

    Verifies that the factory is not in empty state

  2. bool operator!() const noexcept;

    Verifies that the factory is in empty state

  3. attribute_value get_value() const;


    The actual attribute value. It shall not return empty values (exceptions shall be used to indicate errors).

  4. void swap(attribute & that) noexcept;

    The method swaps two factories (i.e. their implementations).

attribute protected member functions

  1. impl * get_impl() const noexcept;


    The pointer to the implementation

  2. void set_impl(intrusive_ptr< impl > p) noexcept;

    Sets the pointer to the factory implementation.



    Pointer to the implementation. Must not be NULL.

attribute friend functions

  1. template<typename T> friend T attribute_cast(attribute const &);

    The function casts one attribute factory to another