Implementation of std::common_type

Содержание

Слайд 2

On topic

Metafunctions using specializations
Metafunctions using SFINAE
Implementation of std::common_type

On topic Metafunctions using specializations Metafunctions using SFINAE Implementation of std::common_type

Слайд 3

Template specialization

template
class container {
T content{};
};
int main() {
container cont1;
container

Template specialization template class container { T content{}; }; int main() {
cont2;
container> cont3;
}

Слайд 4

Template specialization

template
class container {
T content{};
};
int main() {
container cont1; //OK

Template specialization template class container { T content{}; }; int main() {
container cont2; //OK
container> cont3; //OK
}

Слайд 5

Template specialization

struct Special {
Special(int){}
Special() = delete;
};

Template specialization struct Special { Special(int){} Special() = delete; };

Слайд 6

Template specialization

struct Special {
Special(int){}
Special() = delete;
};
template
class container {
T

Template specialization struct Special { Special(int){} Special() = delete; }; template class
content{};
};
int main() {
container cont;
}

Слайд 7

Template specialization

struct Special {
Special(int){}
Special() = delete;
};
template
class container {
T

Template specialization struct Special { Special(int){} Special() = delete; }; template class
content{}; //error: use of deleted function ‘container::container()’
};
int main() {
container cont;
}

Слайд 8

Template specialization

struct Special { /* ... */ };
template
class container { /*

Template specialization struct Special { /* ... */ }; template class container
... */ };
template<>
struct container {
Special content{0};
};
int main() {
container cont;
}

Слайд 9

Template specialization

struct Special { /* ... */ };
template
class container { /*

Template specialization struct Special { /* ... */ }; template class container
... */ };
template<>
struct container {
Special content{0};
};
int main() {
container cont; //OK
}

Слайд 10

std::is_same

template
struct is_same {
static const bool value = false;
};
template

std::is_same template struct is_same { static const bool value = false; };
T>
struct is_same {
static const bool value = true;
};

Слайд 11

std::is_same

template
struct is_same { /* ... */ };
template
struct is_same

std::is_same template struct is_same { /* ... */ }; template struct is_same
T> { /* ... */ };
int main() {
static_assert(is_same::value);
static_assert(not is_same::value);
}

Слайд 12

std::is_same

template
struct is_same { /* ... */ };
template
struct is_same

std::is_same template struct is_same { /* ... */ }; template struct is_same
T> { /* ... */ };
int main() {
static_assert(is_same::value);
static_assert(not is_same::value);
}

Слайд 13

std::is_same

template
struct is_same { /* ... */ };
template
struct is_same

std::is_same template struct is_same { /* ... */ }; template struct is_same
T> { /* ... */ };
int main() {
static_assert(is_same::value);
static_assert(not is_same::value);
}

Слайд 14

std::remove_reference

template
struct remove_reference {
using type = T;
};
template
struct remove_reference {
using

std::remove_reference template struct remove_reference { using type = T; }; template struct
type = T;
};
template
struct remove_reference {
using type = T;
};

Слайд 15

std::remove_reference

template
struct remove_reference {
using type = T;
};
template
struct remove_reference {

std::remove_reference template struct remove_reference { using type = T; }; template struct
// If l-reference
using type = T;
};
template
struct remove_reference {
using type = T;
};

Слайд 16

std::remove_reference

template
struct remove_reference {
using type = T;
};
template
struct remove_reference { //

std::remove_reference template struct remove_reference { using type = T; }; template struct
If l-reference
using type = T;
};
template
struct remove_reference { //If r-reference
using type = T;
};

Слайд 17

std::remove_reference

template
struct remove_reference { //Any other type (not reference)
using type =

std::remove_reference template struct remove_reference { //Any other type (not reference) using type
T;
};
template
struct remove_reference { // If l-reference
using type = T;
};
template
struct remove_reference { //If r-reference
using type = T;
};

Слайд 18

std::remove_reference
// is_same def
// remove_reference def
int main() {
static_assert(is_same::type, int>::value);
static_assert(is_same::type, char**>::value);
static_assert(is_same::type,

std::remove_reference // is_same def // remove_reference def int main() { static_assert(is_same ::type,
bool*>::value);
}

Слайд 19

std::remove_reference

//...
template
struct remove_reference { // If r-reference
using type = T;
};
//...
int main()

std::remove_reference //... template struct remove_reference { // If r-reference using type =
{
static_assert(is_same::type, int>::value);
static_assert(is_same::type, char**>::value);
static_assert(is_same::type, bool*>::value);
}

Слайд 20

std::remove_reference

//...
template
struct remove_reference { // If l-reference
using type = T;
};
//...
int main()

std::remove_reference //... template struct remove_reference { // If l-reference using type =
{
static_assert(is_same::type, int>::value);
static_assert(is_same::type, char**>::value);
static_assert(is_same::type, bool*>::value);
}

Слайд 21

std::remove_reference

//...
template
struct remove_reference { //Any other type (not reference)
using type =

std::remove_reference //... template struct remove_reference { //Any other type (not reference) using
T;
};
//...
int main() {
static_assert(is_same::type, int>::value);
static_assert(is_same::type, char**>::value);
static_assert(is_same::type, bool*>::value);
}

Слайд 22

std::is_const

template
struct is_const {
static const bool value = false;
};
template
struct is_const

std::is_const template struct is_const { static const bool value = false; };
T> {
static const bool value = true;
};

Слайд 23

std::is_function

std::is_function

Слайд 24

std::is_function

std::is_function

Слайд 25

std::is_function

std::is_function

Слайд 26

std::is_function

std::is_function

Слайд 27

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;
};
template

std::is_function template struct is_function { static const bool value = not std::is_const
T>
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

Слайд 28

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

Слайд 29

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);

Слайд 30

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);
static_assert(std::is_same_v);

Слайд 31

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);
static_assert(std::is_same_v);
static_assert(std::is_same_v);

Слайд 32

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);

Слайд 33

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;//Only

std::is_function template struct is_function { static const bool value = not std::is_const
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);

Слайд 34

template
struct is_function {
static const bool value = not std::is_const::value;//Only

template struct is_function { static const bool value = not std::is_const ::value;//Only
functions and references have this trait
};
template
struct is_function {
static const bool value = false;
};
template
struct is_function {
static const bool value = false;
};

using l_ref_t = int&;
using r_ref_t = int&&;
using funct_t = int(char*, bool);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);

template
constexpr bool is_same_v = is_same::value; //since c++14

std::is_function

Слайд 35

std::is_function

template
struct is_function {
static const bool value = not std::is_const::value;
};
template

std::is_function template struct is_function { static const bool value = not std::is_const
T>
struct is_function { //Filtering out l-references
static const bool value = false;
};
template
struct is_function { //Filtering out r-references
static const bool value = false;
};

Слайд 36

std::is_array

template
struct is_array {
static const bool value = false;
};
template
struct is_array

std::is_array template struct is_array { static const bool value = false; };
{
static const bool value = true;
};
template
struct is_array {
static const bool value = true;
};

Слайд 37

std::is_array

template
struct is_array {
static const bool value = false;
};
template
struct is_array

std::is_array template struct is_array { static const bool value = false; };
{ // Specialization for unknown length array type
static const bool value = true;
};
template
struct is_array {
static const bool value = true;
};

Слайд 38

std::is_array

template
struct is_array {
static const bool value = false;
};
template
struct is_array

std::is_array template struct is_array { static const bool value = false; };
{ // Specialization for unknown length array type
static const bool value = true;
};
template
struct is_array { // Specialization for length-known array type
static const bool value = true;
};

Слайд 39

std::is_array

template
struct is_array { // Primary template for non-array types
static const

std::is_array template struct is_array { // Primary template for non-array types static
bool value = false;
};
template
struct is_array { // Specialization for unknown length array type
static const bool value = true;
};
template
struct is_array { // Specialization for length-known array type
static const bool value = true;
};

Слайд 40

std::remove_extent

template
struct remove_extent {
using type = T;
};
template
struct remove_extent

std::remove_extent template struct remove_extent { using type = T; }; template struct
{
using type = T;
};
template
struct remove_extent {
using type = T;
};

Слайд 41

std::remove_extent

template
struct remove_extent {
using type = T;
};
template
struct remove_extent

std::remove_extent template struct remove_extent { using type = T; }; template struct
{
using type = T;
};
template
struct remove_extent {
using type = T;
};

Слайд 42

std::remove_extent

template
struct remove_extent {
using type = T;
};
template
struct remove_extent

std::remove_extent template struct remove_extent { using type = T; }; template struct
{
using type = T;
};
template
struct remove_extent {
using type = T;
};

Слайд 43

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

Слайд 44

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };


Слайд 45

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };


Слайд 46

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type
std::enable_if::type
std::enable_if::type
std::enable_if::type

Слайд 47

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type

Слайд 48

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type

Слайд 49

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error

Слайд 50

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error

Слайд 51

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error

Слайд 52

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error
‘type’ is not a member of ‘std::enable_if

Слайд 53

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error
‘type’ is not a member of ‘std::enable_if

template
using enable_if_t = typename enable_if::type; //since c++11

Слайд 54

std::enable_if

template
struct enable_if;
template
struct enable_if {
using type = IfTrue;
};
template

std::enable_if template struct enable_if; template struct enable_if { using type = IfTrue;
IfTrue>
struct enable_if { };

std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type //OK
std::enable_if::type // Error
‘type’ is not a member of ‘std::enable_if

template
using enable_if_t = typename enable_if::type; //since c++11

Слайд 55

SFINAE (Substitution Fail Is Not An Error)

SFINAE (Substitution Fail Is Not An Error)

Слайд 56

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) {
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5);
foo('x');
}

Слайд 57

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5);
foo('x');
}

Слайд 58

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5);
foo('x');
}

Слайд 59

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5);
foo('x');
}

Слайд 60

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
//enable_if. OK
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5);
foo('x');
}

Слайд 61

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
//enable_if. OK
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x');
}

Слайд 62

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const

std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) {
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x');
}

Слайд 63

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
// Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) {
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x');
}

Слайд 64

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
// Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) {
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x');
}

Слайд 65

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
// Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // enable_if. OK.
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x');
}

Слайд 66

SFINAE (Substitution Failure Is Not An Error)

template
std::enable_if_t, void> foo(const T&) {

SFINAE (Substitution Failure Is Not An Error) template std::enable_if_t , void> foo(const
// Substitution Failure (not member ‘type’ in std::enable_if)
std::cout<<"I'm foo(int)\n";
}
template
std::enable_if_t, void> foo(const T&) { // enable_if. OK.
std::cout<<"I'm foo(char)\n";
}
int main() {
foo(5); // I'm foo(int)
foo('x'); // I'm foo(char)
}

Слайд 67

std::void_t

template
using void_t = void;

std::void_t template using void_t = void;

Слайд 68

std::void_t

template
using void_t = void;
static_assert(std::is_same_v{}.begin())>, void>);

std::void_t template using void_t = void; static_assert(std::is_same_v {}.begin())>, void>);

Слайд 69

std::is_defaut_constructible

std::is_defaut_constructible

Слайд 70

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};

Слайд 71

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};

Слайд 72

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};

Слайд 73

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, int*>::value);

Слайд 74

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, int*>::value);
[T = std::unique_ptr]
[Args... = int*]

Слайд 75

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, int*>::value);
[T = std::unique_ptr]
[Args... = int*] std::unique_ptr(int*{}) //OK

Слайд 76

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, int*>::value);
[T = std::unique_ptr]
[Args... = int*] std::unique_ptr(int*{}) //OK

Слайд 77

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, int*>::value);
[T = std::unique_ptr]
[Args... = int*] std::unique_ptr(int*{})

Слайд 78

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};
static_assert(is_constructible_impl, void, char*>::value);
[T = std::unique_ptr]
[Args... =char*] std::unique_ptr(char*{})

Слайд 79

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> { //SF
static const bool value = true;
};
static_assert(is_constructible_impl, void, char*>::value);
[T = std::unique_ptr]
[Args... =char*] std::unique_ptr(char*{}) //NOT OK

Слайд 80

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; //That’s
const bool value = false; //That’s it!
};
template
struct is_constructible_impl, Args...> { //SF
static const bool value = true;
};
static_assert(is_constructible_impl, void, char*>::value);
[T = std::unique_ptr]
[Args... =char*] std::unique_ptr(char*{}) //NOT OK

Слайд 81

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; //That’s
const bool value = false; //That’s it!
};
template
struct is_constructible_impl, Args...> { //SF
static const bool value = true;
};
static_assert(is_constructible_impl, void, char*>::value); //Assertion fail!
[T = std::unique_ptr]
[Args... =char*] std::unique_ptr(char*{}) //NOT OK

Слайд 82

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value);

Слайд 83

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);
???

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value); ???

Слайд 84

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);
???

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value); ???

Слайд 85

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);
???
template
struct is_constructible : is_constructible_impl

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value); ??? template struct is_constructible : is_constructible_impl { };
{ };

Слайд 86

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);
???
template
struct is_constructible : is_constructible_impl

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value); ??? template struct is_constructible : is_constructible_impl { }; static_assert(is_constructible , int*>::value);
{ };
static_assert(is_constructible, int*>::value);

Слайд 87

std::is_defaut_constructible

static_assert(is_constructible_impl, void, int*>::value);
???
template
struct is_constructible : is_constructible_impl

std::is_defaut_constructible static_assert(is_constructible_impl , void, int*>::value); ??? template struct is_constructible : is_constructible_impl {
{ };
static_assert(is_constructible, int*>::value);
//Looks like all is good...

Слайд 88

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};

Слайд 89

std::declval

template
T&& declval() {};

std::declval template T&& declval() {};

Слайд 90

std::declval

template
T&& declval() {};
static_assert(std::is_same_v()),int&&>);

std::declval template T&& declval() {}; static_assert(std::is_same_v ()),int&&>);

Слайд 91

std::declval

template
T&& declval() {};
static_assert(std::is_same_v()),int&&>);
static_assert(std::is_same_v()),char&>);

std::declval template T&& declval() {}; static_assert(std::is_same_v ()),int&&>); static_assert(std::is_same_v ()),char&>);

Слайд 92

std::declval

template
T&& declval() {};
static_assert(std::is_same_v()),int&&>);
static_assert(std::is_same_v()),char&>);
static_assert(std::is_same_v<
decltype(std::declval>().begin()),
std::vector::iterator>
);

std::declval template T&& declval() {}; static_assert(std::is_same_v ()),int&&>); static_assert(std::is_same_v ()),char&>); static_assert(std::is_same_v decltype(std::declval >().begin()), std::vector ::iterator> );

Слайд 93

std::declval

template
T&& declval() {};
static_assert(std::is_same_v()),int&&>);
static_assert(std::is_same_v()),char&>);
static_assert(std::is_same_v<
decltype(std::declval>().begin()),
std::vector::iterator>
);

std::declval template T&& declval() {}; static_assert(std::is_same_v ()),int&&>); static_assert(std::is_same_v ()),char&>); static_assert(std::is_same_v decltype(std::declval >().begin()), std::vector ::iterator> );

Слайд 94

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl, Args...> {
static const bool value = true;
};

Слайд 95

std::is_defaut_constructible

template< class T, class = void, class... Args>
struct is_constructible_impl {
static const

std::is_defaut_constructible template struct is_constructible_impl { static const bool value = false; };
bool value = false;
};
template
struct is_constructible_impl()...))>, Args...> {
static const bool value = true;
};

Слайд 96

std::common_type

std::common_type

Слайд 97

std::common_type

auto var = true ? bool{} : char{};
What is a type of

std::common_type auto var = true ? bool{} : char{}; What is a type of `var`?
`var`?

Слайд 98

std::common_type

auto var = true ? bool{} : char{}; // bool?
What is a

std::common_type auto var = true ? bool{} : char{}; // bool? What
type of `var`?

Слайд 99

std::common_type

auto var = true ? bool{} : char{}; // bool?
What is a

std::common_type auto var = true ? bool{} : char{}; // bool? What
type of `var`?
bool b{};
std::cin>>b;
auto var2 = b ? bool{} : char{};
What is a type of `var2`?

Слайд 100

std::common_type

auto var = true ? bool{} : char{}; // bool?
What is a

std::common_type auto var = true ? bool{} : char{}; // bool? What
type of `var`?
bool b{};
std::cin>>b;
auto var2 = b ? bool{} : char{}; // ???
What is a type of `var2`?

Слайд 101

std::common_type

auto var = true ? bool{} : char{}; // bool?
What is a

std::common_type auto var = true ? bool{} : char{}; // bool? What
type of `var`? // int !
bool b{};
std::cin>>b;
auto var2 = b ? bool{} : char{}; // ???
What is a type of `var2`? // int !

Слайд 102

std::common_type

How it works?

std::common_type How it works?
Имя файла: Implementation-of-std::common_type.pptx
Количество просмотров: 29
Количество скачиваний: 0