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

User defined type conversions from other vector classes are effectively disabled #72

Closed
btmorex opened this issue Apr 21, 2013 · 1 comment
Assignees
Milestone

Comments

@btmorex
Copy link

btmorex commented Apr 21, 2013

This constructor (and presumably corresponding constructors from different sized vectors):

    template <typename U> 
    GLM_FUNC_DECL explicit tvec2(
        U const & x);

prevents users from implementing type conversions from other vector classes which are very useful. C++ prefers constructors over conversion operators and U will match anything even if the U type cannot be converted to float or double.

So, even if I have the following:

struct my_vec {
operator glm::vec2() { return glm::vec2(x, y); }
float x, y;
};

It will not be used even with static_cast<glm::vec2>(my_vec())

I believe the desired behavior can be achieved with std::enable_if and std::is_convertible (at least for C++11 compilers)

Groovounet pushed a commit that referenced this issue May 5, 2013
@ghost ghost assigned Groovounet May 26, 2013
@Groovounet
Copy link
Member

This bug has been fixed in GLM 0.9.5.branch for GLM 0.9.5.1 release.
The change will generate warnings in case if required conversions but the feature seems relevant.

Thanks,
Christophe

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

No branches or pull requests

2 participants