Adam Badura <
adam.f...@gmail.com> wrote:
> The problem is however, that this makes the few_first_primes value
> far less usable! In particular, you can no longer use it with
> standard containers to initialize them or add values. Below code:
I tried this with clang, and it compiled and worked fine:
//-----------------------------------------------------------
#include <vector>
#include <iostream>
int main()
{
const auto values = { 1, 3, 5, 7 };
for(auto value: values) std::cout << value << "\n";
std::vector<int> vec = values;
for(auto value: vec) std::cout << value << "\n";
}
//-----------------------------------------------------------
Curiously, if I change the 'const' to 'constexpr', it fails to compile,
giving the error:
test.cc:7:20: error: constexpr variable 'values' must be initialized by a
constant expression
constexpr auto values = { 1, 3, 5, 7 };
^ ~~~~~~~~~~~~~~
test.cc:7:20: note: pointer to subobject of temporary is not a constant
expression
test.cc:7:29: note: temporary created here
constexpr auto values = { 1, 3, 5, 7 };
^
If I move 'values' to the global scope, then it works as a constexpr.