Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont declare too many symbols in user namespace #291

Open
1 of 2 tasks
yanminhui opened this issue May 20, 2023 · 3 comments
Open
1 of 2 tasks

Dont declare too many symbols in user namespace #291

yanminhui opened this issue May 20, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@yanminhui
Copy link

yanminhui commented May 20, 2023

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

#define REFLECTION(STRUCT_NAME, ...) \
MAKE_META_DATA(STRUCT_NAME, GET_ARG_COUNT(__VA_ARGS__), __VA_ARGS__)

#define MAKE_META_DATA(STRUCT_NAME, N, ...) \
constexpr inline std::array<frozen::string, N> arr_##STRUCT_NAME = { \
MARCO_EXPAND(MACRO_CONCAT(CON_STR, N)(__VA_ARGS__))}; \
MAKE_META_DATA_IMPL(STRUCT_NAME, \
MAKE_ARG_LIST(N, &STRUCT_NAME::FIELD, __VA_ARGS__))

@qicosmos as above codes show, it may produce many symbols declare in user namespace if many structures need reflection.

Reproduction way

Anything else

possible solution:

#define REFLECTION(T, arg)                                       \
    constexpr auto meta_info(T) {                                \
        struct impl {                                            \
            constexpr const char* props() const { return #arg; } \
        };                                                       \
        return impl{};                                           \
    }

REFLECTION(int, age)
REFLECTION(char, pname)

std::cout << meta_info(int{}).props() << std::endl;
std::cout << meta_info(char{}).props() << std::endl;

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@qicosmos
Copy link
Collaborator

Acctually the main code is a a function now,

#define MAKE_META_DATA_IMPL(STRUCT_NAME, ...) \

@yanminhui
Copy link
Author

MAKE_META_DATA_IMPL

arr_##STRUCT_NAME is outside of MAKE_META_DATA_IMPL.

@poor-circle
Copy link
Collaborator

Thank you, I will fix it later.

@poor-circle poor-circle added the enhancement New feature or request label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants