__COUNTER__ equivalent on Xcode?

I am migrating a project from Linux to Xcode, and I am facing a "version" problem.

I need a unique compile time identifier for my dynamic stuff, on linux I used the __ COUNTER__ preprocessor, but it seems that the gcc 4.2 used in Xcode doesn't know about __ COUNTER__ yet ...
So, I was wondering what I can do to solve this?
I can upgrade GCC to 4.3 (which __ COUNTER__ understands) using macports.org or something like that ... I am very noob on OSX and not very good on linux = [
or find another way to accomplish this, in case method to give a function / variable a unique identifier. I tried with __ LINE__, but after a few days you end up declaring the material on the same line in different files, and playing with this is simply not productive ...

Any help is appreciated!

Thanks
Jonathan

+3
source share
2 answers

@ stinky472: I am using code close to what you wrote above ...

My problem was that I used a macro to declare project namespaces, so having a fully qualified class name, such as class c, is in :: b :: c.
I changed my code to not rely on namespaces, but add a new argument in the class macro declaration to indicate which namespace is used, for example:

newclass (a :: b, c): public d {

};

, , , namespaces, , , ...

,

0

, , " " factory [...]

RTTI ( , ; boost:: any ), ? .

#include <iostream>
#include <string>
using namespace std;

template <class T>
const char* my_type_id()
{
    return "Unknown";
}

#define REGISTER_TYPE(some_type)            \
    template <> inline                      \
    const char* my_type_id<some_type>()     \
    {                                       \
        return #some_type;                  \
    }

REGISTER_TYPE(int)
REGISTER_TYPE(std::string)

int main()
{
    // displays "int"
    cout << my_type_id<int>() << endl;

    // displays "std::string"
    cout << my_type_id<string>() << endl;

    // displays "Unknown" - we haven't registered char
    cout << my_type_id<char>() << endl;
}

, . , , , , ( "std::string", "", .).

boost:: , SDK (, , boost, , , , boost). , boost:: any, ( boost:: variant ), , SDK RTTI (I ' m , RTTI , - ).

, . , std::string, , factory:: create ( "std::string" ); , , factory std::string .

+1

Source: https://habr.com/ru/post/1752020/