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

Full std::type_index interface support #3

Open
foonathan opened this issue Aug 5, 2015 · 7 comments
Open

Full std::type_index interface support #3

foonathan opened this issue Aug 5, 2015 · 7 comments

Comments

@foonathan
Copy link
Contributor

ctti::type_index should have the full interface as std::type_index. Currently only missing the comparison operators.
Also, name() should really return a const char* but this has the null-termination issue discussed in my PR.

@Manu343726
Copy link
Owner

I'm agree with this. About name() returning ctti::detail::string, that was a try in the line of "ctti::detail::string only", the first alternative I was talking about in your PR.

@Manu343726
Copy link
Owner

I have been checking docs from both std::type_index and ctti::type_info. Since ctti features have no runtime overhead, there's no point for me in wrapping a type_info to get a type_index, I would just provide features of both at once (What ctti::type_id_t currently does).

That said, type_id_t misses the before() function from type_info, plus comparison operators. Since the collation order is implementation defined, it offers no order guarantees. I was thinking on using hash for comparison in addition to in/equality. Except from MSVC putting "struct" in front of struct type names, our names should be equal on all platforms, yielding same hash, guaranteeing same type ordering.

@foonathan
Copy link
Contributor Author

Couldn't we remove the prefix to have the same name? Otherwise I agree.

@Manu343726
Copy link
Owner

Of course we can, but it may be expensive:

if(name.substr<0,8>() == "struct ")
    return name.substr<8,name.size()>();
else
    return name;

@foonathan
Copy link
Contributor Author

Then pack an #ifdef _MSC_VER around it :D

Maybe you can avoid the branch then completely, is the struct before each type?

@Manu343726
Copy link
Owner

No, for classes it prepends class, and no prefix is added for basic types. If struct and class had the same length we could use a trait to check for prefix. Also is not that simple since when the type has cv qualifiers struct/class is no longer a prefix.

@foonathan
Copy link
Contributor Author

Damn, then at least make the check only on MSVC. A hash that doesn't change with the platform would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants