@ProCxx

Страница 1412 из 2477
Constantine
17.10.2017
00:27:13
вроде я проверил и (а) они не делают

так что (б)

void assign(const Optional& src) { if (src.hasValue()) { assign(src.value()); } else { clear(); } }

реализация из folly закономерно проверяет hasValue

Google
Ioann V
17.10.2017
00:29:27
Такая проверка стоит чего то

Constantine
17.10.2017
00:29:44
Хм... вообще-то если ее не сделать то код UB

Ioann V
17.10.2017
00:30:33
А у них там указатели или чего ?

Constantine
17.10.2017
00:30:48
Там union у всех

Ioann V
17.10.2017
00:32:39
И правая часть может быть неинициализирована ?

Constantine
17.10.2017
00:32:42
А, гоню, в folly там std::aligned_storage

Да, может

Ioann V
17.10.2017
00:40:14
Можешь скинуть что за типы там ?

Вот что говорит стандарт на эту тему

Admin


Ioann V
17.10.2017
00:43:24
an expression evaluating to an indeterminate value causes undefined behavior, with certain exceptions (8.5p12)unsigned char (and possibly char, if unsigned) is the exceptionvariables with automatic storage duration and whose types have trivial default initialization initially have indeterminate values (5.3.4p17)

Constantine
17.10.2017
00:45:54
Хм... там реализация optional<T>

Ioann V
17.10.2017
00:46:25
For any object (other than a base-class subobject) of trivially copyable type T, whether or not the object holds a valid value of type T, the underlying bytes (1.7) making up the object can be copied into an array of char or unsigned char. If the content of the array of char or unsigned char is copied back into the object, the object shall subsequently hold its original value.

Google
Ioann V
17.10.2017
00:46:56
For any trivially copyable type T, if two pointers to T point to distinct T objects obj1 and obj2, where neither obj1 nor obj2 is a base-class subobject, if the underlying bytes (1.7) making up obj1 are copied into obj2, obj2 shall subsequently hold the same value as obj1. [ Example: T* t1p; T* t2p; // provided that t2p points to an initialized object ... std::memcpy(t1p, t2p, sizeof(T)); // at this point, every subobject of trivially copyable type in *t1p contains // the same value as the corresponding subobject in *t2p —end example ]

Arithmetic types (3.9.1), enumeration types, pointer types, pointer to member types (3.9.2), std::nullptr_- t, and cv-qualified versions of these types (3.9.3) are collectively called scalar types. Scalar types, POD classes (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called POD types. Cv-unqualified scalar types, trivially copyable class types (Clause 9), arrays of such types, and nonvolatile const-qualified versions of these types (3.9.3) are collectively called trivially copyable types

A trivially copyable class is a class that: (6.1) — has no non-trivial copy constructors (12.8), (6.2) — has no non-trivial move constructors (12.8), (6.3) — has no non-trivial copy assignment operators (13.5.3, 12.8), (6.4) — has no non-trivial move assignment operators (13.5.3, 12.8), and (6.5) — has a trivial destructor (12.4).

Страница 1412 из 2477