1

Topic: Variable name in a kompajl-time

Greetings! Prompt, , whether the subject in any of the future standards is planned? Thanks.

2

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> greetings! And ours to you X> prompt, , whether the subject in any of the future standards is planned? Well, as though a name of a variable and now in a kompajl-time. Or what you mean? X> thanks.

3

Re: Variable name in a kompajl-time

Hello, Marty, you wrote: M> Well, as though a name of a variable and now in a kompajl-time. Or what you mean? int var; constexpr const char *varname = get_var_name (var);

4

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> X> int var; X> constexpr const char *varname = get_var_name (var); X> And now it is possible #define get_var_name (var) #var

5

Re: Variable name in a kompajl-time

Hello, watchmaker, you wrote: so I know it, therefore I ask about the standard

6

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> so I know it, therefore I ask about the standard So it already is in the standard. What to plan? What you would like? Certainly in the future is planned to add in c ++ the best support of a reflection. But here it is is specific this part it is already accessible and  very long time ago.

7

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> greetings! X> prompt, , whether the subject in any of the future standards is planned? I so understand we search for analog C# nameof? Than a macro not a variant? We tell such for elimination of errors of type NAMEOF (123): #define NAMEOF (variable) ((decltype (&variable)) nullptr, #variable) https://stackoverflow.com/a/38697366/558098

8

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> greetings! X> prompt, , whether the subject in any of the future standards is planned? X> thanks. And now we watch closely hands, nervous to blink: https://ideone.com/erQjVI #include <iostream> #include <regex> template <typename T, T& var> std:: string get_variable_name () {std:: string str (__ PRETTY_FUNCTION __); std:: smatch match; std:: regex pattern ("T& var = (\\w +)"); std:: regex_search (str, match, pattern); return match [1];} char char_1; int int_2; double double_3; float float_4; std:: string string_5; int main () {std:: cout <<get_variable_name <decltype (char_1), char_1> () <<std:: endl; std:: cout <<get_variable_name <decltype (int_2), int_2> () <<std:: endl; std:: cout <<get_variable_name <decltype (double_3), double_3> () <<std:: endl; std:: cout <<get_variable_name <decltype (float_4), float_4> () <<std:: endl; std:: cout <<get_variable_name <decltype (string_5), string_5> () <<std:: endl;} Output: char_1 int_2 double_3 float_4 string_5 Who after that tells, what in a C ++ there is no reflection?

9

Re: Variable name in a kompajl-time

Hello, rg45, you wrote: X>> greetings! X>> prompt, , whether the subject in any of the future standards is planned? X>> thanks. R> and now we watch closely hands, nervous to blink: R> https://ideone.com/erQjVI R> R> char char_1; R> int int_2; R> double double_3; R> float float_4; R> std:: string string_5; R> Who after that tells, what in a C ++ there is no reflection? And if it inside main to place?

10

Re: Variable name in a kompajl-time

Hello, night beast, you wrote: R>> R>> char char_1; R>> int int_2; R>> double double_3; R>> float float_4; R>> std:: string string_5; NB> NB> and if it inside main to place? Easily: https://ideone.com/RsSisx

11

Re: Variable name in a kompajl-time

Hello, rg45, you wrote: On a basis __ PRETTY_FUNCTION __ whole CTTI it is written: the link

12

Re: Variable name in a kompajl-time

Hello, YuriV, you wrote: YV> Hello, rg45, you wrote: YV> On a basis __ PRETTY_FUNCTION __ whole CTTI it is written: the link this Is a pity just not compile time, one of the few  microsoft that __ FUNSIG __ (the analog __ PRETTY_FUNCTION __) can be interposed in #pragma message (__ FUNCSIG __) and to receive messages at a compilation stage.

13

Re: Variable name in a kompajl-time

Hello, niXman, you wrote: X> greetings! X> prompt, , whether the subject in any of the future standards is planned? X> thanks. Generally it would be desirable iterated behavior, as it is meant a reflection. struct my_struct {inline void my_func (int arg1, int arg2);}; template <typename a C, typename R, typename... Args> auto std:: bind (R a C::*fptr func) {# pragma message (get_arg_identifier <1, decltype (func)> ()) return bind_impl (func);} and generally possibility to receive compile expressions template <typename Arg> inline auto foo (Arg arg) {expr_of <decltype (arg)>:: type expr; do_something_with_expression <decltype (arg)> (); return expr (1, 2, 3);} void foomain () {int x0 = 0, x1 = 1, x2 = 2; foo (x0 * (x2 + x1));} Herein  on variables is the considerable profit Now in everyones  and   \and other template time expressions it becomes through , and it is not enough that with it it is possible to do.