Modernize uses of POD types (#2120)

* modernize uses of POD types

* update isocpp.dic
This commit is contained in:
Jan Schultke
2023-10-12 21:55:10 +02:00
committed by GitHub
parent 77680bff2b
commit e694c3cd04
2 changed files with 15 additions and 13 deletions

View File

@@ -3188,7 +3188,7 @@ A `struct` of many (individually cheap-to-move) elements might be in aggregate e
##### Exceptions ##### Exceptions
* For non-concrete types, such as types in an inheritance hierarchy, return the object by `unique_ptr` or `shared_ptr`. * For non-concrete types, such as types in an inheritance hierarchy, return the object by `unique_ptr` or `shared_ptr`.
* If a type is expensive to move (e.g., `array<BigPOD>`), consider allocating it on the free store and return a handle (e.g., `unique_ptr`), or passing it in a reference to non-`const` target object to fill (to be used as an out-parameter). * If a type is expensive to move (e.g., `array<BigTrivial>`), consider allocating it on the free store and return a handle (e.g., `unique_ptr`), or passing it in a reference to non-`const` target object to fill (to be used as an out-parameter).
* To reuse an object that carries capacity (e.g., `std::string`, `std::vector`) across multiple calls to the function in an inner loop: [treat it as an in/out parameter and pass by reference](#Rf-out-multi). * To reuse an object that carries capacity (e.g., `std::string`, `std::vector`) across multiple calls to the function in an inner loop: [treat it as an in/out parameter and pass by reference](#Rf-out-multi).
##### Example ##### Example
@@ -10860,7 +10860,7 @@ The *always initialize* rule is a style rule aimed to improve maintainability as
Here is an example that is often considered to demonstrate the need for a more relaxed rule for initialization Here is an example that is often considered to demonstrate the need for a more relaxed rule for initialization
widget i; // "widget" a type that's expensive to initialize, possibly a large POD widget i; // "widget" a type that's expensive to initialize, possibly a large trivial type
widget j; widget j;
if (cond) { // bad: i and j are initialized "late" if (cond) { // bad: i and j are initialized "late"
@@ -18440,21 +18440,22 @@ Specialization offers a powerful mechanism for providing alternative implementat
This is a simplified version of `std::copy` (ignoring the possibility of non-contiguous sequences) This is a simplified version of `std::copy` (ignoring the possibility of non-contiguous sequences)
struct pod_tag {}; struct trivially_copyable_tag {};
struct non_pod_tag {}; struct non_trivially_copyable_tag {};
template<class T> struct copy_trait { using tag = non_pod_tag; }; // T is not "plain old data" // T is not trivially copyable
template<class T> struct copy_trait { using tag = non_trivially_copyable_tag; };
template<> struct copy_trait<int> { using tag = pod_tag; }; // int is "plain old data" // int is trivially copyable
template<> struct copy_trait<int> { using tag = trivially_copyable_tag; };
template<class Iter> template<class Iter>
Out copy_helper(Iter first, Iter last, Iter out, pod_tag) Out copy_helper(Iter first, Iter last, Iter out, trivially_copyable_tag)
{ {
// use memmove // use memmove
} }
template<class Iter> template<class Iter>
Out copy_helper(Iter first, Iter last, Iter out, non_pod_tag) Out copy_helper(Iter first, Iter last, Iter out, non_trivially_copyable_tag)
{ {
// use loop calling copy constructors // use loop calling copy constructors
} }
@@ -18462,7 +18463,8 @@ This is a simplified version of `std::copy` (ignoring the possibility of non-con
template<class Iter> template<class Iter>
Out copy(Iter first, Iter last, Iter out) Out copy(Iter first, Iter last, Iter out)
{ {
return copy_helper(first, last, out, typename copy_trait<Value_type<Iter>>::tag{}) using tag_type = typename copy_trait<std::iter_value_t<Iter>>;
return copy_helper(first, last, out, tag_type{})
} }
void use(vector<int>& vi, vector<int>& vi2, vector<string>& vs, vector<string>& vs2) void use(vector<int>& vi, vector<int>& vi2, vector<string>& vs, vector<string>& vs2)
@@ -18475,10 +18477,10 @@ This is a general and powerful technique for compile-time algorithm selection.
##### Note ##### Note
When `concept`s become widely available such alternatives can be distinguished directly: With C++20 constraints, such alternatives can be distinguished directly:
template<class Iter> template<class Iter>
requires Pod<Value_type<Iter>> requires std::is_trivially_copyable_v<std::iter_value_t<Iter>>
Out copy_helper(In, first, In last, Out out) Out copy_helper(In, first, In last, Out out)
{ {
// use memmove // use memmove

View File

@@ -57,7 +57,7 @@ AUTOSAR
b2 b2
BDE BDE
behaviorless behaviorless
BigPOD BigTrivial
Bjarne Bjarne
blog blog
Bloomberg Bloomberg