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

Author Topic: Add sf::String::at(), analagous to std::string::at()  (Read 5297 times)

0 Members and 1 Guest are viewing this topic.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Add sf::String::at(), analagous to std::string::at()
« on: July 10, 2016, 05:40:14 pm »
The title has it :)
That's what happens when you don't follow guidelines  :'(
https://github.com/SFML/SFML/issues/1110
« Last Edit: July 10, 2016, 05:57:08 pm by xqbt »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #1 on: July 10, 2016, 06:22:45 pm »
What exactly is your use case for this feature?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #2 on: July 10, 2016, 06:30:47 pm »
The same as for sf::string::at(). Does a range check and throws an exception in case of violation. My use case exactly? Well, I am writing a program that uses SFML and I am drawing out arrays of sf::Strings (and modifying those strings too) and using at() would have already saved me some crashes.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #3 on: July 12, 2016, 07:39:45 pm »
It's a questionable way of error handling, like checking every pointer against null before dereferencing it, or checking divisors against 0...

Reasonable implementations of the STL (which is used internally by sf::String) provide you with assertions for such cases. They show you all your logic errors when debugging, but you get full speed in Release mode and don't need to clutter code with try-catch blocks, to which you can't even meaningfully react, as the bug shouldn't exist in the first place.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #4 on: July 13, 2016, 09:22:12 pm »
Just as a tiny suggestion. You could just use std::string instead of sf::String for string storing/manipulation.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #5 on: July 23, 2016, 08:05:57 pm »
Just as a tiny suggestion. You could just use std::string instead of sf::String for string storing/manipulation.
And SFML could do that too, but there's a good reason it doesnt, so I don't either ;)
It's a questionable way of error handling, like checking every pointer against null before dereferencing it, or checking divisors against 0...

Reasonable implementations of the STL (which is used internally by sf::String) provide you with assertions for such cases. They show you all your logic errors when debugging, but you get full speed in Release mode and don't need to clutter code with try-catch blocks, to which you can't even meaningfully react, as the bug shouldn't exist in the first place.
That would be great!
All I am saying is this code should break:
sf::String s("A");
std::cout << s[1] << std::endl;
« Last Edit: July 23, 2016, 08:08:46 pm by xqbt »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Add sf::String::at(), analagous to std::string::at()
« Reply #6 on: July 23, 2016, 09:31:45 pm »
Quote
And SFML could do that too, but there's a good reason it doesnt, so I don't either
sf::String is mostly meant for automatic conversions, ie. SFML classes and functions take a sf::String so that whatever you pass to them, it ends up in a known encoding. sf::String is not made for string manipulation. So no, because SFML uses it doesn't mean that you have to use it as well. These are two very different use cases.
Laurent Gomila - SFML developer

 

anything