-1

After some time implementing my own streambuf I askes myself if you can use different types for the basic_streambuf like double. Are there any experiences and use cases here?

Gustavo
  • 919
  • 11
  • 34
  • What is the *actual* problem you try to solve with your `streambuf` class? *Why* do you need it to store its data in `double`? Please read about [the XY problem](http://xyproblem.info/) and think about how it relates to this question. – Some programmer dude Jun 16 '17 at 09:43

1 Answers1

3

You're missing the point of streambuf. It's the back end of std::stream. The front end is provided by operator<< and operator>>. Those are overloaded for double. The frond end converts any type to characters, the back end does the I/O (to file, screen, network, whatever)

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • What about not using characters in the backend but double. What if there is no need to store characters. – Gustavo Jun 16 '17 at 09:38
  • @Gustavo: how would you write a `std::string` to such a backend? Remember, `std::streambuf` is part of the whole `` library. If your use case differs too much from the typical uses of ``, you'll find limited benefit in adapting ``. – MSalters Jun 16 '17 at 09:41
  • So it is right that only characters are allowed in the iostream environment and it was never intended using other types than char? – Gustavo Jun 16 '17 at 09:54
  • @Gustavo: Well, there's `wchar_t`. But yes, it's all about characters. – MSalters Jun 16 '17 at 09:57
  • @Gustavo any `T` for which `std::char_traits` has sensible members – Caleth Jun 16 '17 at 10:56