comptime/returnvector.cpp
The following code example is taken from the book
C++20 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2021
The code is licensed under a
Creative Commons Attribution 4.0 International License.
//
raw code
#include
<vector>
constexpr
auto
returnVector()
{
std::vector<
int
> v{0, 8, 15};
v.push_back(42);
//...
return
v;
}
constexpr
auto
returnVectorSize()
{
auto
coll = returnVector();
return
coll.size();
}
int
main()
{
//constexpr auto coll = returnVector();
// ERROR
constexpr
auto
tmp = returnVectorSize();
// OK
//...
}