I take what I said earlier. I think I might have a way to make this work in pure c / C ++, albeit in a very dirty way. You would need to pass a pointer to your functions ...
i.e. bool hello_world (std :: string and my_string, const std :: string * const my_string_ptr) {
bool hello_world (std :: string my_string, const std :: string * const my_string_ptr) {
if you tested
if (& my_string == my_string_ptr)
It would evaluate true if var was passed by reference, and false if it was passed by value .
Of course, doubling your variables in all of your functions is probably not worth it ...
Johannes is right ... not in pure C ++. But you CAN do it. The trick is to cheat. Use the built-in scripting language, such as perl, to find the source. Here's the perl built-in module:
http://perldoc.perl.org/perlembed.html
Pass it the name of the function, the name of the variable, and the location of the source, and then use the regular expression to find the variable and check its type. In fact, this may be the best solution for your code as a whole, if you always have a source.
I will post a function for this basic approach a bit ... you need to take care of some morning work! :)
Even if you do not want to distribute the source, you can create some kind of packed function data file / var, which you could parse through @runtime and get an equivalent result.
Change 1
For example, using the # I32 match(SV *string, char *pattern) function in the Perl Embed tutorial, you can do something like:
bool is_reference(const char * source_loc, const char * function_name, const char * variable_name) { std::ifstream my_reader; char my_string[256]; SV * perl_line_contents; bool ret_val = false; char my_pattern [400]=strcat("m/.*",function_name); my_pattern=strcat(my_pattern, ".*[,\s\t]*"); my_pattern=strcat(my_pattern, variable_name); my_pattern=strcat(my_pattern, "[\s\t]*[\(,].*$"); my_reader.open(source_loc.c_str()); while (!my_reader.eof()) { my_reader.getline(my_string,256); sv_setpv(perl_line_contents,my_string); if(match(perl_line_contents,my_pattern)) { ret_val= true; } } return ret_val; }
... there are ... two ways to do this (see update above).