Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Vector2/3::Type typedef  (Read 2804 times)

0 Members and 1 Guest are viewing this topic.

Gauth

  • Newbie
  • *
  • Posts: 4
    • View Profile
sf::Vector2/3::Type typedef
« on: January 22, 2015, 02:21:07 pm »
Hi there !
Would it be possible to add a simple typedef in Vector2/3 describing the type the vector use ?
For example it would be nice for use in template function/class :
template <typename Vec>
Vec::Type addCoordinate(Vec vec)
{
    return x + y;
}
 

I know in C++11 we can use decltype to do that but i don't find it pleasant to read :
template <typename Vec>
decltype(Vec::x) addCoordinate(Vec vec)
{
    return x + y;
}
 

One line can "simplify" a lot of lines !
Thanks :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Vector2/3::Type typedef
« Reply #1 on: January 22, 2015, 02:25:46 pm »
Laurent Gomila - SFML developer

Gauth

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: sf::Vector2/3::Type typedef
« Reply #2 on: January 22, 2015, 02:45:55 pm »
Sorry, I made some search before posting but I found nothing (bad keyword).

And why isn't that possible ? I assume it break no code. I understand you say "no" to larger features that are not in the range of features SFML provides. But, between
sf::Vector2i::Type
and
TypeOfVector<sf::Vector2i>::type
the first one is much clearer. And I think clear code is better in general.

Sorry to bother you with that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Vector2/3::Type typedef
« Reply #3 on: January 22, 2015, 02:58:43 pm »
I don't say "no", I'm just showing a very simple solution that doesn't require to modify SFML. If you still think that this should be added to the API, the discussion is open.

If you want more clarity, here is a more "standard" naming:
vector_traits<T>::type
Laurent Gomila - SFML developer

Gauth

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: sf::Vector2/3::Type typedef
« Reply #4 on: January 22, 2015, 03:17:44 pm »
I have no more argument, clarity was my only one :P So this discussion ends there.

Thank you anyway and good afternoon !

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: sf::Vector2/3::Type typedef
« Reply #5 on: January 22, 2015, 03:18:03 pm »
I'm curious, what is your use case for this?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gauth

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: sf::Vector2/3::Type typedef
« Reply #6 on: January 22, 2015, 03:55:05 pm »
Some templated vector functions like length and dot product. Also I use 64-bit int vectors, when possible, without differentiating the vector type name, so in some case, for example when storing one of the component into a temporary variable, I have to know the underlying type (32-bit or 64-bit). I admit the later problem is not very SFML-related, so I understand Laurent when he hesitate on the relevance of such feature (I understand now that's very specific to my problem).

 

anything