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;








1















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










share|improve this question






















  • 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

















1















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










share|improve this question






















  • 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













1












1








1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer

























    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer





























      1














      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.






      share|improve this answer



























        1












        1








        1







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 22 at 2:33

























        answered Mar 22 at 2:22









        Dmytro DadykaDmytro Dadyka

        1,3511721




        1,3511721





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현