Boost logo

Boost :

Subject: [boost] [utility] Proposal to extract some components from Boost.Log
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-08-28 04:14:51


I'd like to extract some general-purpose components from Boost.Log to
Boost.Utility so that they could be used in other libraries and user's code
that is not related to logging. The components are mostly standalone
already and are not tied to Boost.Log specifics.

1. BOOST_EXPLICIT_OPERATOR_BOOL() macro for defining explicit operator
bool() for a class. For C++03 compilers the macro implements safe bool
idiom or just a regular operator bool(), if the compiler doesn't handle
safe bool well. The generated operator is implemented in terms of
operator!(), which should be defined for the class:

  template< typename T >
  class my_ptr
    T* m_p;

    bool operator! () const
      return !m_p;

Various different implementations of explicit/safe bool operator are
present in different libraries. It would be good to unify them.

Implementation: boost/log/utility/explicit_operator_bool.hpp

2. basic_string_literal< CharT, CharTraitsT > class template. String
literal is similar to string_ref, but it only allows to be constructed from
a string literal. Obviously, it doesn't allow to modify the literal and it
doesn't allocate memory for the literal. It supports clear() though, which
makes the literal object to refer to an empty literal. Otherwise it
provides interface similar to std::string.

Docs: <
Implementation: boost/log/utility/string_literal.hpp

3. type_info_wrapper class. The class wraps a reference to std::type_info
and provides equality and ordering operators. The wrapper implements value
semantics (i.e. it can be constructed and copied), which allows it to be
stored in containers, including as keys.

Docs: <
Implementation: boost/log/utility/type_info_wrapper.hpp

4. empty_deleter class. The class can be used as a deleter (e.g. for
shared_ptr) that does nothing. It can be useful in some cases, when you
need a shared_ptr but you know you will delete the referred object by other
means. For example, with Boost.Log this deleter can be used to create
shared_ptr< std::ostream > to std::cout. Another use case is to create a
weak_ptr to an object to be able to test whether the object has already
been deleted.

Implementation: boost/log/utility/empty_deleter.hpp

5. BOOST_LOG_UNIQUE_IDENTIFIER_NAME(prefix) macro. This macro expands in a
unique (within the current TU) token that starts with prefix. This can be
useful for declaring unique variable and type names within other macros.
Not that this macro has much value but it could be useful for other
libraries that define macros.

Implementation: boost/log/utility/unique_identifier_name.hpp

Boost list run by bdawes at, gregod at, cpdaniel at, john at