1) Is there a way to declare static constexpr char []inside struct/ class?
Yes; it's simple.
Below is a complete working example
struct bar
{ static constexpr char value[] = "foo"; };
constexpr char bar::value[];
int main ()
{
std::cout << bar::value << std::endl;
}
I assume you forgot the line bar::value[].
2) 1) , static constexpr char *????
.
3) static const char [] - ?
, ; C- ++ 11 std::array
4) , , , "" [...] , char std::array: (
( , ++ 14, ++ 11), "Hell", .
std::make_index_sequence std::index_sequence, char[] std::array.
template <std::size_t Dim, std::size_t ... Is>
constexpr std::array<char, Dim> gceH (char const (&str)[Dim],
std::index_sequence<Is...> const &)
{ return { { str[Is]... } }; }
template <std::size_t Dim>
constexpr std::array<char, Dim> getConstExpr (char const (&str)[Dim])
{ return gceH(str, std::make_index_sequence<Dim>{}); }
int main ()
{
constexpr auto f = getConstExpr("Hell");
static_assert( 5U == f.size(), "!" );
}
- EDIT -
Swift (!), , char, getConstExpr() .
So getConstExpr(), (gceH()) :
template <typename T, std::size_t Dim, std::size_t ... Is>
constexpr std::array<T, Dim> gceH (T const (&str)[Dim],
std::index_sequence<Is...> const &)
{ return { { str[Is]... } }; }
template <typename T, std::size_t Dim>
constexpr std::array<T, Dim> getConstExpr (T const (&str)[Dim])
{ return gceH(str, std::make_index_sequence<Dim>{}); }