Code like the initialization of `s2` isn't uncommon, especially for initialization that's a bit more complicated than `square()`.
However, compared to the initialization of `s3` there are two problems:
@ -13148,25 +13148,25 @@ Consider a popular technique for providing a handle for storing small objects in
struct Scoped { // store a T in Scoped
// ...
T obj;
};
};
template<typenameT>
struct On_heap { // store a T in on the free store
struct On_heap { // store a T on the free store
// ...
T* objp;
};
};
template<typenameT>
using Handle = typename std::conditional<(sizeof(T)<=on_stack_max),
Scoped<T>, // first alternative
On_heap<T>// second alternative
>::type;
using Handle = typename std::conditional<(sizeof(T)<=on_stack_max),
Scoped<T>, // first alternative
On_heap<T>// second alternative
>::type;
void f()
{
Handle<double> v1; // the double goes on the stack
Handle<std::array<double,200>> v2; // the array goes on the free store
// ...
Handle<double> v1; // the double goes on the stack
Handle<std::array<double,200>> v2; // the array goes on the free store
// ...
}
Assume that `Scoped` and `On_heap` provide compatible user interfaces.
@ -13476,7 +13476,7 @@ Making `surface_readings` be `const` (with respect to this function) allow reaso
Immutable data can be safely and efficiently shared.
No locking is needed: You can't have a data race on a constant.
See also [CP.mess: Message Passing](#SScp-messs) and [CP.31: prefer pass by value](#C#Rconc-data-by-value).
See also [CP.mess: Message Passing](#SScp-mess) and [CP.31: prefer pass by value](#C#Rconc-data-by-value).
##### Enforcement
@ -18651,7 +18651,7 @@ Use `gsl::span` for non-owning references into a container.
Comparing the performance of a fixed-sized array allocated on the stack against a `vector` with its elements on the free store is bogus.
You could just as well compare a `std::array` on the stack against the result of a `malloc()` accessed through a pointer.
For most code, even the difference between stack allocation and free-store allocation doesn't matter, but the convenieance and safety of `vector` does.
For most code, even the difference between stack allocation and free-store allocation doesn't matter, but the convenience and safety of `vector` does.
People working with code for which that difference matters are quite capable of choosing between `array` and `vector`.