userver: utils::StrongTypedef< Tag, T, Ops, class > Class Template Reference
Loading...
Searching...
No Matches
utils::StrongTypedef< Tag, T, Ops, class > Class Template Reference

Detailed Description

template<class Tag, class T, StrongTypedefOps Ops, class>
class utils::StrongTypedef< Tag, T, Ops, class >

Strong typedef for a type T.

Typical usage:

Or:

struct MyString final : utils::StrongTypedef<MyString, std::string> {
using StrongTypedef::StrongTypedef;
};

Has all the:

  • comparison (see "Operators" below)
  • hashing
  • streaming operators
  • optimizaed logging for LOG_XXX()

If used with container-like type also has common STL functions:

  • begin()
  • end()
  • cbegin()
  • cend()
  • size()
  • empty()
  • clear()
  • operator[]

Operators: You can customize the operators that are available by passing the third argument of type StrongTypedefOps. See its docs for more info.

Examples
postgresql/functional_tests/basic_chaos/postgres_service.cpp, samples/digest_auth_service/auth_digest.cpp, samples/postgres_auth/auth_bearer.cpp, samples/postgres_auth/user_info_cache.hpp, samples/postgres_service/postgres_service.cpp, and samples/s3api/src/s3api_client.cpp.

Definition at line 177 of file strong_typedef.hpp.

+ Inheritance diagram for utils::StrongTypedef< Tag, T, Ops, class >:

Public Types

using UnderlyingType = T
 
using TagType = Tag
 

Public Member Functions

 StrongTypedef (const StrongTypedef &)=default
 
 StrongTypedef (StrongTypedef &&) noexcept=default
 
StrongTypedefoperator= (const StrongTypedef &)=default
 
StrongTypedefoperator= (StrongTypedef &&) noexcept=default
 
constexpr StrongTypedef (impl::strong_typedef::InitializerList< T > lst)
 
template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>>
constexpr StrongTypedef (Args &&... args) noexcept(noexcept(T(std::forward< Args >(args)...)))
 
constexpr operator const T & () const &noexcept
 
constexpr operator T () &&noexcept
 
constexpr operator T& () &noexcept
 
constexpr const T & GetUnderlying () const &noexcept
 
constexprGetUnderlying () &&noexcept
 
constexpr T & GetUnderlying () &noexcept
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<T, Void>>
auto begin ()
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<T, Void>>
auto end ()
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto begin () const
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto end () const
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto cbegin () const
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto cend () const
 
template<typename Void = void, typename = impl::strong_typedef::EnableIfSizeable<const T, Void>>
auto size () const
 
auto empty () const
 
auto clear ()
 
template<class Arg >
decltype(autooperator[] (Arg &&i)
 
template<class Arg >
decltype(autooperator[] (Arg &&i) const
 

Static Public Attributes

static constexpr StrongTypedefOps kOps = Ops
 

Member Typedef Documentation

◆ TagType

template<class Tag , class T , StrongTypedefOps Ops, class >
using utils::StrongTypedef< Tag, T, Ops, class >::TagType = Tag

Definition at line 186 of file strong_typedef.hpp.

◆ UnderlyingType

template<class Tag , class T , StrongTypedefOps Ops, class >
using utils::StrongTypedef< Tag, T, Ops, class >::UnderlyingType = T

Definition at line 185 of file strong_typedef.hpp.

Constructor & Destructor Documentation

◆ StrongTypedef() [1/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr utils::StrongTypedef< Tag, T, Ops, class >::StrongTypedef ( impl::strong_typedef::InitializerList< T > lst)
inlineconstexpr

Definition at line 195 of file strong_typedef.hpp.

◆ StrongTypedef() [2/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>>
constexpr utils::StrongTypedef< Tag, T, Ops, class >::StrongTypedef ( Args &&... args)
inlineexplicitconstexprnoexcept

Definition at line 198 of file strong_typedef.hpp.

Member Function Documentation

◆ begin() [1/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::begin ( )
inline

Definition at line 217 of file strong_typedef.hpp.

◆ begin() [2/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::begin ( ) const
inline

Definition at line 227 of file strong_typedef.hpp.

◆ cbegin()

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::cbegin ( ) const
inline

Definition at line 237 of file strong_typedef.hpp.

◆ cend()

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::cend ( ) const
inline

Definition at line 242 of file strong_typedef.hpp.

◆ clear()

template<class Tag , class T , StrongTypedefOps Ops, class >
auto utils::StrongTypedef< Tag, T, Ops, class >::clear ( )
inline

Definition at line 253 of file strong_typedef.hpp.

◆ empty()

template<class Tag , class T , StrongTypedefOps Ops, class >
auto utils::StrongTypedef< Tag, T, Ops, class >::empty ( ) const
inline

Definition at line 251 of file strong_typedef.hpp.

◆ end() [1/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::end ( )
inline

Definition at line 222 of file strong_typedef.hpp.

◆ end() [2/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfRange<const T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::end ( ) const
inline

Definition at line 232 of file strong_typedef.hpp.

◆ GetUnderlying() [1/3]

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr T utils::StrongTypedef< Tag, T, Ops, class >::GetUnderlying ( ) &&
inlineconstexprnoexcept

Definition at line 213 of file strong_typedef.hpp.

◆ GetUnderlying() [2/3]

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr T & utils::StrongTypedef< Tag, T, Ops, class >::GetUnderlying ( ) &
inlineconstexprnoexcept

Definition at line 214 of file strong_typedef.hpp.

◆ GetUnderlying() [3/3]

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr const T & utils::StrongTypedef< Tag, T, Ops, class >::GetUnderlying ( ) const &
inlineconstexprnoexcept

Definition at line 212 of file strong_typedef.hpp.

◆ operator const T &()

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr utils::StrongTypedef< Tag, T, Ops, class >::operator const T & ( ) const &
inlineexplicitconstexprnoexcept

Definition at line 208 of file strong_typedef.hpp.

◆ operator T()

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr utils::StrongTypedef< Tag, T, Ops, class >::operator T ( ) &&
inlineexplicitconstexprnoexcept

Definition at line 209 of file strong_typedef.hpp.

◆ operator T&()

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr utils::StrongTypedef< Tag, T, Ops, class >::operator T& ( ) &
inlineexplicitconstexprnoexcept

Definition at line 210 of file strong_typedef.hpp.

◆ operator[]() [1/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<class Arg >
decltype(auto) utils::StrongTypedef< Tag, T, Ops, class >::operator[] ( Arg && i)
inline

Definition at line 256 of file strong_typedef.hpp.

◆ operator[]() [2/2]

template<class Tag , class T , StrongTypedefOps Ops, class >
template<class Arg >
decltype(auto) utils::StrongTypedef< Tag, T, Ops, class >::operator[] ( Arg && i) const
inline

Definition at line 260 of file strong_typedef.hpp.

◆ size()

template<class Tag , class T , StrongTypedefOps Ops, class >
template<typename Void = void, typename = impl::strong_typedef::EnableIfSizeable<const T, Void>>
auto utils::StrongTypedef< Tag, T, Ops, class >::size ( ) const
inline

Definition at line 247 of file strong_typedef.hpp.

Member Data Documentation

◆ kOps

template<class Tag , class T , StrongTypedefOps Ops, class >
constexpr StrongTypedefOps utils::StrongTypedef< Tag, T, Ops, class >::kOps = Ops
staticconstexpr

Definition at line 187 of file strong_typedef.hpp.


The documentation for this class was generated from the following file: