Github   Telegram
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
strong_typedef.hpp File Reference

Strong typedef for a type T. More...

#include <functional>
#include <iosfwd>
#include <type_traits>
#include <utility>
#include <fmt/format.h>
#include <userver/utils/fmt_compat.hpp>
#include <boost/functional/hash_fwd.hpp>
#include <userver/formats/common/meta.hpp>
#include <userver/utils/meta.hpp>
#include <userver/utils/underlying_value.hpp>
#include <userver/utils/void_t.hpp>
+ Include dependency graph for strong_typedef.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  utils::StrongTypedef< Tag, T, Ops, class >
 Strong typedef for a type T. More...
 
struct  std::hash<::utils::StrongTypedef< Tag, T, Ops > >
 
struct  fmt::formatter< T, Char, std::enable_if_t<::utils::IsStrongTypedef< T >{}> >
 

Namespaces

namespace  logging
 Logging macro and utilities.
 
namespace  utils
 Utilities.
 

Macros

#define UTILS_STRONG_TYPEDEF_REL_OP(OPERATOR)
 

Typedefs

template<class Tag , class T >
using utils::NonLoggable = StrongTypedef< Tag, T, StrongTypedefOps::kCompareStrong|StrongTypedefOps::kNonLoggable >
 

Enumerations

enum class  utils::StrongTypedefOps {
  kNoCompare = 0 ,
  utils::kCompareStrong = 1 ,
  utils::kCompareTransparentOnly = 2 ,
  utils::kCompareTransparent = 3 ,
  utils::kNonLoggable = 4
}
 

Functions

constexpr bool utils::operator& (StrongTypedefOps op, StrongTypedefOps mask) noexcept
 
constexpr auto utils::operator| (StrongTypedefOps op1, StrongTypedefOps op2) noexcept
 
template<class Tag , class T , StrongTypedefOps Ops>
std::ostream & utils::operator<< (std::ostream &os, const StrongTypedef< Tag, T, Ops > &v)
 Ostreams and Logging. More...
 
template<class Tag , class T , StrongTypedefOps Ops>
logging::LogHelperutils::operator<< (logging::LogHelper &os, const StrongTypedef< Tag, T, Ops > &v)
 
template<class Tag , class T , StrongTypedefOps Ops>
constexpr decltype(auto) utils::UnderlyingValue (const StrongTypedef< Tag, T, Ops > &v) noexcept
 
template<class Tag , class T , StrongTypedefOps Ops>
constexpr T utils::UnderlyingValue (StrongTypedef< Tag, T, Ops > &&v) noexcept
 
constexpr bool utils::IsStrongTypedefLoggable (StrongTypedefOps Ops)
 
template<typename Tag , typename T , StrongTypedefOps Ops, typename Enable , typename ValueType >
std::enable_if_t< formats::common::kIsFormatValue< ValueType >, StrongTypedef< Tag, T, Ops, Enable > > utils::Parse (const ValueType &source, formats::parse::To< StrongTypedef< Tag, T, Ops, Enable > >)
 
template<typename Tag , typename T , StrongTypedefOps Ops, typename Enable , typename TargetType >
TargetType utils::Serialize (const StrongTypedef< Tag, T, Ops, Enable > &object, formats::serialize::To< TargetType >)
 
template<typename Tag , typename T , StrongTypedefOps Ops, typename Enable , typename StringBuilder >
void utils::WriteToStream (const StrongTypedef< Tag, T, Ops, Enable > &object, StringBuilder &sw)
 
template<typename Tag , StrongTypedefOps Ops>
std::string utils::ToString (const StrongTypedef< Tag, std::string, Ops > &object)
 
template<typename Tag , typename T , StrongTypedefOps Ops, typename = std::enable_if_t<meta::kIsInteger<T>>>
std::string utils::ToString (const StrongTypedef< Tag, T, Ops > &object)
 
template<typename Target , typename Tag , typename T , StrongTypedefOps Ops, typename Enable >
constexpr Target utils::StrongCast (const StrongTypedef< Tag, T, Ops, Enable > &src)
 
template<typename Target , typename Tag , typename T , StrongTypedefOps Ops, typename Enable >
constexpr Target utils::StrongCast (StrongTypedef< Tag, T, Ops, Enable > &&src)
 
template<class Tag , class T , StrongTypedefOps Ops>
std::size_t utils::hash_value (const StrongTypedef< Tag, T, Ops > &v)
 

Detailed Description

Strong typedef for a type T.

Definition in file strong_typedef.hpp.

Macro Definition Documentation

◆ UTILS_STRONG_TYPEDEF_REL_OP

#define UTILS_STRONG_TYPEDEF_REL_OP (   OPERATOR)
Value:
template <class Tag1, class T1, StrongTypedefOps Ops1, class Tag2, class T2, \
StrongTypedefOps Ops2> \
constexpr bool operator OPERATOR(const StrongTypedef<Tag1, T1, Ops1>&, \
const StrongTypedef<Tag2, T2, Ops2>&) { \
static_assert(!sizeof(T1), "Comparing those StrongTypedefs is forbidden"); \
return false; \
} \
\
template <class Tag, class T, StrongTypedefOps Ops> \
constexpr std::enable_if_t<Ops & StrongTypedefOps::kCompareStrong, bool> \
operator OPERATOR(const StrongTypedef<Tag, T, Ops>& lhs, \
const StrongTypedef<Tag, T, Ops>& rhs) { \
return lhs.GetUnderlying() OPERATOR rhs.GetUnderlying(); \
} \
\
template <class Tag, class T, StrongTypedefOps Ops, class Other> \
constexpr impl::strong_typedef::EnableTransparentCompare<Tag, T, Ops, Other> \
operator OPERATOR(const StrongTypedef<Tag, T, Ops>& lhs, const Other& rhs) { \
return lhs.GetUnderlying() OPERATOR rhs; \
} \
\
template <class Tag, class T, StrongTypedefOps Ops, class Other> \
constexpr impl::strong_typedef::EnableTransparentCompare<Tag, T, Ops, Other> \
operator OPERATOR(const Other& lhs, const StrongTypedef<Tag, T, Ops>& rhs) { \
return lhs OPERATOR rhs.GetUnderlying(); \
}

Definition at line 264 of file strong_typedef.hpp.