Why Fmtflags are specified twice - once as part of an enum, and another instance as a static const variableInteger storage - Hexadecimal/OctalToken parser semantic actionSigned Hexadecimal to decimal in C++C++ make numbers appear in hexadecimalDecimal to Hex converter using Recursion (C++)Dec Okt Hex table c++?operator[] compiler error and warningConvert decimal string to hex string without storing into intergerConvert string (can be a decimal string or hex string) to integer C++Conversion from int to enum class type possible?
declaring a variable twice in IIFE
Are there any consumables that function as addictive (psychedelic) drugs?
Are tax years 2016 & 2017 back taxes deductible for tax year 2018?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
Compute hash value according to multiplication method
How can I hide my bitcoin transactions to protect anonymity from others?
Draw simple lines in Inkscape
How to add power-LED to my small amplifier?
Set-theoretical foundations of Mathematics with only bounded quantifiers
Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).
Email Account under attack (really) - anything I can do?
Possibly bubble sort algorithm
What typically incentivizes a professor to change jobs to a lower ranking university?
Why don't electron-positron collisions release infinite energy?
Pronouncing Dictionary.com's W.O.D "vade mecum" in English
What defenses are there against being summoned by the Gate spell?
Why can't I see bouncing of a switch on an oscilloscope?
How can I fix this gap between bookcases I made?
Can I make popcorn with any corn?
Copenhagen passport control - US citizen
How is this relation reflexive?
Can a German sentence have two subjects?
Book about a traveler who helps planets in need
Why Fmtflags are specified twice - once as part of an enum, and another instance as a static const variable
Integer storage - Hexadecimal/OctalToken parser semantic actionSigned Hexadecimal to decimal in C++C++ make numbers appear in hexadecimalDecimal to Hex converter using Recursion (C++)Dec Okt Hex table c++?operator[] compiler error and warningConvert decimal string to hex string without storing into intergerConvert string (can be a decimal string or hex string) to integer C++Conversion from int to enum class type possible?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
In the STD library file ios_base.h we see the following:
enum _Ios_Fmtflags
_S_boolalpha = 1L << 0,
_S_dec = 1L << 1,
_S_fixed = 1L << 2,
_S_hex = 1L << 3,
_S_internal = 1L << 4,
_S_left = 1L << 5,
_S_oct = 1L << 6,
_S_right = 1L << 7,
_S_scientific = 1L << 8,
_S_showbase = 1L << 9,
_S_showpoint = 1L << 10,
_S_showpos = 1L << 11,
_S_skipws = 1L << 12,
_S_unitbuf = 1L << 13,
_S_uppercase = 1L << 14,
_S_adjustfield = _S_left ;
But after that we also see:
/// Insert/extract @c bool in alphabetic rather than numeric format.
static const fmtflags boolalpha = _S_boolalpha;
/// Converts integer input or generates integer output in decimal base.
static const fmtflags dec = _S_dec;
/// Generate floating-point output in fixed-point notation.
static const fmtflags fixed = _S_fixed;
/// Converts integer input or generates integer output in hexadecimal base.
static const fmtflags hex = _S_hex;
Why are they using static const in addition to the enum values to represent the same values? Why can't we just use the enum values? And isn't using static wasteful in this case considering those are const values?
Thanks,
Ofer
c++ std
add a comment |
In the STD library file ios_base.h we see the following:
enum _Ios_Fmtflags
_S_boolalpha = 1L << 0,
_S_dec = 1L << 1,
_S_fixed = 1L << 2,
_S_hex = 1L << 3,
_S_internal = 1L << 4,
_S_left = 1L << 5,
_S_oct = 1L << 6,
_S_right = 1L << 7,
_S_scientific = 1L << 8,
_S_showbase = 1L << 9,
_S_showpoint = 1L << 10,
_S_showpos = 1L << 11,
_S_skipws = 1L << 12,
_S_unitbuf = 1L << 13,
_S_uppercase = 1L << 14,
_S_adjustfield = _S_left ;
But after that we also see:
/// Insert/extract @c bool in alphabetic rather than numeric format.
static const fmtflags boolalpha = _S_boolalpha;
/// Converts integer input or generates integer output in decimal base.
static const fmtflags dec = _S_dec;
/// Generate floating-point output in fixed-point notation.
static const fmtflags fixed = _S_fixed;
/// Converts integer input or generates integer output in hexadecimal base.
static const fmtflags hex = _S_hex;
Why are they using static const in addition to the enum values to represent the same values? Why can't we just use the enum values? And isn't using static wasteful in this case considering those are const values?
Thanks,
Ofer
c++ std
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06
add a comment |
In the STD library file ios_base.h we see the following:
enum _Ios_Fmtflags
_S_boolalpha = 1L << 0,
_S_dec = 1L << 1,
_S_fixed = 1L << 2,
_S_hex = 1L << 3,
_S_internal = 1L << 4,
_S_left = 1L << 5,
_S_oct = 1L << 6,
_S_right = 1L << 7,
_S_scientific = 1L << 8,
_S_showbase = 1L << 9,
_S_showpoint = 1L << 10,
_S_showpos = 1L << 11,
_S_skipws = 1L << 12,
_S_unitbuf = 1L << 13,
_S_uppercase = 1L << 14,
_S_adjustfield = _S_left ;
But after that we also see:
/// Insert/extract @c bool in alphabetic rather than numeric format.
static const fmtflags boolalpha = _S_boolalpha;
/// Converts integer input or generates integer output in decimal base.
static const fmtflags dec = _S_dec;
/// Generate floating-point output in fixed-point notation.
static const fmtflags fixed = _S_fixed;
/// Converts integer input or generates integer output in hexadecimal base.
static const fmtflags hex = _S_hex;
Why are they using static const in addition to the enum values to represent the same values? Why can't we just use the enum values? And isn't using static wasteful in this case considering those are const values?
Thanks,
Ofer
c++ std
In the STD library file ios_base.h we see the following:
enum _Ios_Fmtflags
_S_boolalpha = 1L << 0,
_S_dec = 1L << 1,
_S_fixed = 1L << 2,
_S_hex = 1L << 3,
_S_internal = 1L << 4,
_S_left = 1L << 5,
_S_oct = 1L << 6,
_S_right = 1L << 7,
_S_scientific = 1L << 8,
_S_showbase = 1L << 9,
_S_showpoint = 1L << 10,
_S_showpos = 1L << 11,
_S_skipws = 1L << 12,
_S_unitbuf = 1L << 13,
_S_uppercase = 1L << 14,
_S_adjustfield = _S_left ;
But after that we also see:
/// Insert/extract @c bool in alphabetic rather than numeric format.
static const fmtflags boolalpha = _S_boolalpha;
/// Converts integer input or generates integer output in decimal base.
static const fmtflags dec = _S_dec;
/// Generate floating-point output in fixed-point notation.
static const fmtflags fixed = _S_fixed;
/// Converts integer input or generates integer output in hexadecimal base.
static const fmtflags hex = _S_hex;
Why are they using static const in addition to the enum values to represent the same values? Why can't we just use the enum values? And isn't using static wasteful in this case considering those are const values?
Thanks,
Ofer
c++ std
c++ std
asked Mar 22 at 0:53
Ofer RozentswiegOfer Rozentswieg
61
61
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06
add a comment |
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06
add a comment |
1 Answer
1
active
oldest
votes
The goal is to separate the interface and implementation. _Ios_Fmtflags
is implementation-defined and can be changed in the future, ios_base
should not be significantly dependent on _Ios_Fmtflags
, but must provide a set of constants as part of the documented interface see comment. How could we avoid code dependency on the internal _Ios_Fmtflags
implementation? We can use synonyms for _Ios_Fmtflags
type and constant objects of this type which is done further:
typedef _Ios_Fmtflags fmtflags;
static const fmtflags boolalpha = _S_boolalpha;
static const fmtflags dec = _S_dec;
Now only these lines depend on the specific _Ios_Fmtflags
implementation. For example, we can rename _S_boolalpha
and it will not affect the code except only one line static const fmtflags boolalpha = _S_boolalpha;
Or as another example, we can replace enum _Ios_Fmtflags
by integer or some else suitable type. A very useful technique that makes the code maintaining much easier, although it increases the code size.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291357%2fwhy-fmtflags-are-specified-twice-once-as-part-of-an-enum-and-another-instance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The goal is to separate the interface and implementation. _Ios_Fmtflags
is implementation-defined and can be changed in the future, ios_base
should not be significantly dependent on _Ios_Fmtflags
, but must provide a set of constants as part of the documented interface see comment. How could we avoid code dependency on the internal _Ios_Fmtflags
implementation? We can use synonyms for _Ios_Fmtflags
type and constant objects of this type which is done further:
typedef _Ios_Fmtflags fmtflags;
static const fmtflags boolalpha = _S_boolalpha;
static const fmtflags dec = _S_dec;
Now only these lines depend on the specific _Ios_Fmtflags
implementation. For example, we can rename _S_boolalpha
and it will not affect the code except only one line static const fmtflags boolalpha = _S_boolalpha;
Or as another example, we can replace enum _Ios_Fmtflags
by integer or some else suitable type. A very useful technique that makes the code maintaining much easier, although it increases the code size.
add a comment |
The goal is to separate the interface and implementation. _Ios_Fmtflags
is implementation-defined and can be changed in the future, ios_base
should not be significantly dependent on _Ios_Fmtflags
, but must provide a set of constants as part of the documented interface see comment. How could we avoid code dependency on the internal _Ios_Fmtflags
implementation? We can use synonyms for _Ios_Fmtflags
type and constant objects of this type which is done further:
typedef _Ios_Fmtflags fmtflags;
static const fmtflags boolalpha = _S_boolalpha;
static const fmtflags dec = _S_dec;
Now only these lines depend on the specific _Ios_Fmtflags
implementation. For example, we can rename _S_boolalpha
and it will not affect the code except only one line static const fmtflags boolalpha = _S_boolalpha;
Or as another example, we can replace enum _Ios_Fmtflags
by integer or some else suitable type. A very useful technique that makes the code maintaining much easier, although it increases the code size.
add a comment |
The goal is to separate the interface and implementation. _Ios_Fmtflags
is implementation-defined and can be changed in the future, ios_base
should not be significantly dependent on _Ios_Fmtflags
, but must provide a set of constants as part of the documented interface see comment. How could we avoid code dependency on the internal _Ios_Fmtflags
implementation? We can use synonyms for _Ios_Fmtflags
type and constant objects of this type which is done further:
typedef _Ios_Fmtflags fmtflags;
static const fmtflags boolalpha = _S_boolalpha;
static const fmtflags dec = _S_dec;
Now only these lines depend on the specific _Ios_Fmtflags
implementation. For example, we can rename _S_boolalpha
and it will not affect the code except only one line static const fmtflags boolalpha = _S_boolalpha;
Or as another example, we can replace enum _Ios_Fmtflags
by integer or some else suitable type. A very useful technique that makes the code maintaining much easier, although it increases the code size.
The goal is to separate the interface and implementation. _Ios_Fmtflags
is implementation-defined and can be changed in the future, ios_base
should not be significantly dependent on _Ios_Fmtflags
, but must provide a set of constants as part of the documented interface see comment. How could we avoid code dependency on the internal _Ios_Fmtflags
implementation? We can use synonyms for _Ios_Fmtflags
type and constant objects of this type which is done further:
typedef _Ios_Fmtflags fmtflags;
static const fmtflags boolalpha = _S_boolalpha;
static const fmtflags dec = _S_dec;
Now only these lines depend on the specific _Ios_Fmtflags
implementation. For example, we can rename _S_boolalpha
and it will not affect the code except only one line static const fmtflags boolalpha = _S_boolalpha;
Or as another example, we can replace enum _Ios_Fmtflags
by integer or some else suitable type. A very useful technique that makes the code maintaining much easier, although it increases the code size.
edited Mar 22 at 2:33
answered Mar 22 at 2:22
Dmytro DadykaDmytro Dadyka
1,3511721
1,3511721
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291357%2fwhy-fmtflags-are-specified-twice-once-as-part-of-an-enum-and-another-instance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The enums look like they're only for internal use.
– Passer By
Mar 22 at 1:30
It's probably for type compatibility.
– Mark Ransom
Mar 22 at 2:06