noexcept c 2b 2b

Solutions on MaxInterview for noexcept c 2b 2b by the best coders in the world

showing results for - "noexcept c 2b 2b"
Alberto
28 Jun 2020
1#include <iostream>
2#include <utility>
3#include <vector>
4 
5void may_throw();
6void no_throw() noexcept;
7auto lmay_throw = []{};
8auto lno_throw = []() noexcept {};
9class T{
10public:
11  ~T(){} // dtor prevents move ctor
12         // copy ctor is noexcept
13};
14class U{
15public:
16  ~U(){} // dtor prevents move ctor
17         // copy ctor is noexcept(false)
18  std::vector<int> v;
19};
20class V{
21public:
22  std::vector<int> v;
23};
24 
25int main()
26{
27 T t;
28 U u;
29 V v;
30 
31 std::cout << std::boolalpha
32           << "Is may_throw() noexcept? " << noexcept(may_throw()) << '\n'
33           << "Is no_throw() noexcept? " << noexcept(no_throw()) << '\n'
34           << "Is lmay_throw() noexcept? " << noexcept(lmay_throw()) << '\n'
35           << "Is lno_throw() noexcept? " << noexcept(lno_throw()) << '\n'
36           << "Is ~T() noexcept? " << noexcept(std::declval<T>().~T()) << '\n'
37           // note: the following tests also require that ~T() is noexcept because
38           // the expression within noexcept constructs and destroys a temporary
39           << "Is T(rvalue T) noexcept? " << noexcept(T(std::declval<T>())) << '\n'
40           << "Is T(lvalue T) noexcept? " << noexcept(T(t)) << '\n'
41           << "Is U(rvalue U) noexcept? " << noexcept(U(std::declval<U>())) << '\n'
42           << "Is U(lvalue U) noexcept? " << noexcept(U(u)) << '\n'  
43           << "Is V(rvalue V) noexcept? " << noexcept(V(std::declval<V>())) << '\n'
44           << "Is V(lvalue V) noexcept? " << noexcept(V(v)) << '\n';  
45}