How to use "use" for a function? for instance
class A; void f(int); struct B { using BA = A; using Bf = f; ??? };
You can do
struct B { using BA = A; constexpr static auto Bf = f; }
This way, you donβt have to worry about specifying a type that can be annoying.
, . , , . , , , Bf f, . constexpr .
Bf
f
constexpr
f - , -:
void (*Bf)(int) = f;
:
void Bf(int i) { f(i); }
, , B.
B
f , , :
template <class... Args> auto Bf(Args&&... args) -> decltype(::f(std::forward<Args>(args)...)) noexcept(noexcept(::f(std::forward<Args>(args...)))) { return ::f(std::forward<Args>(args)...); }
... .
, , f.
++ 14 :
struct B { using BA = A; static constexpr auto BF = [](auto&&... args) { return f(std::forward<decltype(args)>(args)...); }; };
, - std::forward . std::forward, ( , , f ):
std::forward
struct B { using BA = A; static constexpr auto BF = [](auto... args) { return f(args...); }; };
, A - , f - . using Bf f, :
A
using
using Bf = decltype(f);
Source: https://habr.com/ru/post/1014270/More articles:Posting JSON WebAPI Data - jsonintrinsically safe data group several times - scalaHow to avoid exchanges and UDF during session processing in Spark? - apache-sparkPython virtual environment activation in Atom - pythonChanging a value in two different Angular 2 components at the same time - angularHow to determine if a copy of Local is needed - c #Is there a way to get LinqPad to work with the EF Core context? - linqpadWhy do some lisps put a function name outside the argument list in a function definition? - lispUsing System.Device in an MVC project - c #Extracting the last word from many columns of a data frame (R) - rAll Articles