Skip to content

Instantly share code, notes, and snippets.

@michaelbartnett
Created August 1, 2018 17:29
Show Gist options
  • Save michaelbartnett/e1ba88d3035bf2dba445238a522794b6 to your computer and use it in GitHub Desktop.
Save michaelbartnett/e1ba88d3035bf2dba445238a522794b6 to your computer and use it in GitHub Desktop.

Revisions

  1. michaelbartnett created this gist Aug 1, 2018.
    31 changes: 31 additions & 0 deletions strweird.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #include <string>

    #define STR1 "Hello"
    //#define STR2 "World"
    #define STR2 "12345678123456781234567812345678"
    //#define STR2 "Worlda"

    #define METHOD 3

    std::string get_value(const bool b)
    {
    #if METHOD == 1
    std::string ret;
    if (b) {
    ret = STR1;
    } else {
    ret = STR2;
    }
    return ret;
    #elif METHOD == 2
    if (b) {
    return STR1;
    } else {
    return STR2;
    }
    #elif METHOD == 3
    return b ? STR1 : STR2;
    #elif METHOD == 4
    return b ? STR1 : "World";
    #endif
    }