3

I know that ios_base has a declaration of states for streams like
ios_base::goodbit(error state)
ios_base::ate(file open mode state)
and many more.
What I'm interested in knowing is the definition of these member functions of ios_base
Are they a simple class or a class template? How are they implemented? Which one is there parent class(if any)?

Fiju
  • 416
  • 1
  • 5
  • 11

3 Answers3

3

Are they a simple class or a class template?

They are actually static constexpr declarations nested in the std::ios_base class (as from the reference documentation):

enter image description here

How are they implemented? Which one is there parent class(if any)?

As mentioned there, it's compiler implementation specific. Usually these are simple values without usage of a parent class.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • For what it's worth, there is no total freedom in the implementation, but as one can see in screenshot they have to be bitmask type which has some constraints. But I am not even sure if this counts as a nitpick. – luk32 Jan 16 '15 at 17:37
1

They are not "member functions", they are just some constants.

As you can find in standard library headers, goodbit is a constant with type iostate, and ate is a constant with type openmode.

i.e. libc++ defines them in header "ios":

typedef unsigned int iostate;
static const iostate goodbit = 0x0;
...
typedef unsigned int openmode;
static const openmode ate    = 0x02;
Windoze
  • 321
  • 2
  • 13
1

Technically speaking they are BitmaskType constexpr. Defined in ios_base namespace.

Bitmask type is defined in standard (this is c++14 working draft).

17.5.2.1.3 Bitmask types [bitmask.types]

[...] Each bitmask type can be implemented as an enumerated type that overloads certain operators, as an integer type, or as a bitset (20.5).

This means, even though there is a bitset compilers still have some freedom how to implement it.

The precise definition of the members you ask about is defined in 27.5.3.1 Types [ios.types], and relevant points basically say they are bitmask types.

luk32
  • 15,812
  • 38
  • 62