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

Author Topic: sf::Texture as a template argument  (Read 1462 times)

0 Members and 1 Guest are viewing this topic.

lol123

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::Texture as a template argument
« on: December 09, 2013, 04:16:06 pm »
I made my own Tuple class:

template <class T1, class T2>
class Tuple
{
public:
    Tuple (T1 Item1, T2 Item2) : item1(Item1), item2(Item2) { }
    T1 item1;
    T2 item2;
};

But when I use it:
Tuple<MyOwnClass, sf::Texture>

I get error:
template argument 2 is invalid

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
Re: sf::Texture as a template argument
« Reply #1 on: December 09, 2013, 04:42:48 pm »
Such an error can come from more than just the template (e.g. cyclic dependencies), could you provide a complete and minimal example with the template?

Secondly, is this class just for learning purposes or why aren't you using std::pair?

And finally, you should not be storing a full texture that way. Textures are heavy resources. If you simply assign an texture to your tuple it will make a copy. Copying a texture is really a bad idea, because it involves moving the data from the VRAM to the RAM and back to the VRAM.
At best you should wrap the texture in a smart pointer (unique_ptr or shared_ptr), bundle it to your class/type with a std::pair and put it into a STL container. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lol123

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Texture as a template argument
« Reply #2 on: December 09, 2013, 05:33:21 pm »
1) Just tried to reproduce this error, but everything worked fine! Guess I did something wrong that time
2) I was trying to benchmark my Tuple and std::pair performance

Thanks!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Texture as a template argument
« Reply #3 on: December 09, 2013, 07:36:45 pm »
I was trying to benchmark my Tuple and std::pair performance
You will lose, already because you copy the parameters unnecessarily, let alone move semantics or perfect forwarding. Don't reinvent the wheels of the standard library, they have lived through years of research, development and optimization. Even something seemingly simple like std::pair is non-trivial to implement safely and efficiently.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything