Skip to content

Instantly share code, notes, and snippets.

@jdee
Last active June 21, 2019 17:31
Show Gist options
  • Save jdee/480a7ca8a6637ce28ee7b5b5b34a60a4 to your computer and use it in GitHub Desktop.
Save jdee/480a7ca8a6637ce28ee7b5b5b34a60a4 to your computer and use it in GitHub Desktop.
constexpr (C++11)
#include <iostream>
#include <string>
using namespace std;
struct ConstexprTest
{
static bool const s_bool = true ;
static int const s_int = 42 ;
#ifdef USING_CONSTEXPR
static constexpr const char* const s_charPtr = "abc";
#else
static const char* const s_charPtr;
#endif // USING_CONSTEXPR
static string const s_string ;
};
#ifndef USING_CONSTEXPR
const char* const ConstexprTest::s_charPtr = "abc";
#endif // USING_CONSTEXPR
string const ConstexprTest::s_string = "xyz";
int
main(int argc, char **argv)
{
cout << "s_bool = " << ConstexprTest::s_bool << endl;
cout << "s_int = " << ConstexprTest::s_int << endl;
cout << "s_charptr = " << ConstexprTest::s_charPtr << endl;
cout << "s_string = " << ConstexprTest::s_string << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment