xmllmx
xmllmx

Reputation: 42369

How to use std::fpos?

On the 27.5.4 of the latest C++ standard draft, I find a weird template class std::fpos, but I don't know what it is intended for. (The documentation is vague, less informative, and hard to understand.)

I'm writing my own mini-STL for embedded systems, where I cannot use the compiler-provided STL because of its non-portability. So, I must understand what it means.

For example, I want to use C++11 to develop a linux kernel module, in this case, you cannot direct use any compiler-provided C++ standard library, no matter whether you use clang, gcc, or vc++. None is portable to the linux kernel. So, I have to implement a minimal STL from scratch.

Is there any example to illustrate how to use std::fpos?

Upvotes: 3

Views: 1416

Answers (1)

Dietmar Kühl
Dietmar Kühl

Reputation: 153915

std::fpos<StateT> is used to represent a position in a stream, including the conversion state, i.e., the std::mbstate_t or it replacement for user provided character types. You can use std::pos<StateT> to restore the position of seekable streams, notably file streams. It is the result of the various seek operations on streams and is used as the argument for the seek operations seeking to an absolute position.

In principle, std::fpos<StateT> represent just a byte position in a stream. For streams travelling in the internal representation, i.e., where no encoding/decoding is needed, the byte position is probably all it stores. When file streams enter the picture, the position may be massive (i.e., bigger than could be represented with built-in integers in C++98 which only required 32 bits; std::fpos<StateT> was part of the standard since the first version) and the external encoding may be different than the internal one, requiring to capture encoding state.

Upvotes: 6

Related Questions