Nov 17, 2019 at 12:11am UTC
I'm looking for a set of personal-to-[methods/functions] data fields. A library or something that I can include and activate to give these fields would be nice.
Nov 17, 2019 at 1:21pm UTC
What is a "personal-to-[methods/functions] data field"?
Nov 17, 2019 at 3:29pm UTC
sorry,... variables that give like a functions argument list and all similar data to methods and functions
Nov 17, 2019 at 4:38pm UTC
Can you show us an example of what you mean?
Nov 17, 2019 at 8:47pm UTC
Variables that give like a functions argument list and all similar data to methods and functions
Okay - a way to separate a list of arguments from something
Callable :
https://en.cppreference.com/w/cpp/named_req/Callable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <tuple>
#include <iostream>
#include <functional>
int sum(int a, int b) { return a + b; }
struct foo
{
int product(int m) const { return n_ * m; }
int n_ = 2;
};
int main()
{
{
auto args = std::make_tuple(2, 3);
std::cout << std::apply(sum, args) << '\n' ;
}
{
foo f;
auto args = std::make_tuple(std::cref(f), 3);
std::cout << std::apply(&foo::product, args) << '\n' ;
// alternatively
std::cout << std::invoke(&foo::product, std::cref(f), 3) << '\n' ;
}
}
http://coliru.stacked-crooked.com/a/80f35a8017b3ab94
Unfortunately, building/manipulating std::tuple often requires a little bit of meta-programming know-how: the indices trick, etc.
Last edited on Nov 17, 2019 at 8:47pm UTC
Nov 17, 2019 at 11:40pm UTC
I believe the OP is refering to either std::variant
or some sort of custom implementation of setters and geters. aka. fields. (very small classes for that purpose)