C++11 std::is_nothrow_copy_assignable














































C++11 std::is_nothrow_copy_assignable



Description:
The std::is_nothrow_copy_assignable template of C++ STL is used to check whether type has a copy assignment operator that is known to the compiler not to throw or not.

boolalpha -: used to convert bool values into its textual representation.

Syntax:
template <class T> struct is_nothrow_copy_assignable;

Parameter:
It takes T(Trait class) as a parameter


Code:

#include <iostream>
#include <type_traits>
using namespace std;

struct A { };        //simple structure

struct B                     //structure with copy assingment operator
{ 
B& operator= (const B&) {return *this;} 
};

struct C		//structure with exception
{ 
C& operator= (const C&) noexcept {return *this;} 
};

int main() {
  cout << boolalpha;
  cout << "is_nothrow_copy_assignable:" <<endl<<endl;
  cout << "int: " << std::is_nothrow_copy_assignable<int>::value << std::endl;
  cout << "A: " << std::is_nothrow_copy_assignable<A>::value << std::endl;
  cout << "B: " << std::is_nothrow_copy_assignable<B>::value << std::endl;
  cout << "C: " << std::is_nothrow_copy_assignable<C>::value << std::endl;
  return 0;
}

Output:

=>using boolalpha


=>without using boolalpha



Comments