ugmisc 0.2-76
Miscellaneous C++ header library
Loading...
Searching...
No Matches
static_member_value< Access, T > Struct Template Reference

#include <ugmisc/member.hpp>

Public Types

using safe_matched_type = ???
using matched_type = ???

Static Public Member Functions

template<class F, class... A>
static constexpr decltype(auto) get (F &&default_get, A &&...args)
static constexpr auto & get ()

Static Public Attributes

static constexpr bool has_member = ???

Detailed Description

template<class Access, class... T>
struct static_member_value< Access, T >

Finds a reference to a named static member value in the first type among T... which has a static value accessible by that name.

The Access is responsible for knowing the name to use, and is a type declared with the help of the UGMISC_DECL_MEMBER_ACCESS macro.

For example:

UGMISC_DECL_MEMBER_ACCESS(FooAccessor, foo); // Declares FooAccessor.
auto& foo1 = Getter::get(); // Error if Getter::has_member is false.
decltype(auto) foo2 = Getter::get( defaultFoo, 1, 2 );
#define UGMISC_DECL_MEMBER_ACCESS(TNAME, NAME)
Definition member.hpp:165
Definition member.hpp:1557

In the example above, the value of foo1 will be the first of the following which is valid:

  1. A reference to X::foo.
  2. A reference to Y::foo.

If neither of those is valid, the declaration is an error.

The value of foo2 will be the first valid value of the following:

  1. The same as foo1
  2. defaultFoo(1, 2)
Template Parameters
AccessA type declared using UGMISC_DECL_MEMBER_ACCESS. This is responsible for accessing the correctly named static member, according to the second argument passed to the macro.
TThe types in which to look for the named member.

Member Typedef Documentation

◆ matched_type

template<class Access, class... T>
using static_member_value< Access, T >::matched_type = ???

The type whose named static member would be referenced by get(), if there is one. This member type is not declared if has_member is false.

◆ safe_matched_type

template<class Access, class... T>
using static_member_value< Access, T >::safe_matched_type = ???

The type whose named static member would be referenced by get(), if there is one, or void if there is not.

See also
matched_type, has_member

Member Function Documentation

◆ get() [1/2]

template<class Access, class... T>
constexpr auto & static_member_value< Access, T >::get ( )
inlinestaticconstexpr
Returns
A reference to the found static member.
See also
get(F&& default_get, A&&...args)

◆ get() [2/2]

template<class Access, class... T>
template<class F, class... A>
constexpr decltype(auto) static_member_value< Access, T >::get ( F && default_get,
A &&... args )
staticconstexpr

Like get() but with a default value. The value is provided by a callable parameter, which is passed the args.

This way side effects of getting the default value can be avoided if it is not needed.

Parameters
default_getA function or callable object.
argsOptional arguments to pass to default_get.

Member Data Documentation

◆ has_member

template<class Access, class... T>
bool static_member_value< Access, T >::has_member = ???
staticconstexpr

true if one of the types in T... has a member value accessed by Access.


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