C++ Library Extensions 2022.12.09
To help learn modern C++ programming
013-alias_noexcept.cpp
Go to the documentation of this file.
1#include <tpf_output.hpp>
2
3/*
4 If you want to pass an argument as
5 template parameter, that argument should be
6 compile-time expression, or constexpr
7*/
8template<auto FuncType, typename... ArgTypes>
9constexpr auto is_noexcept_v = noexcept(FuncType(std::declval<ArgTypes>()...));
10
11int sum(int a, int b) noexcept
12{
13 return a + b;
14}
15
16int summation(int a, int b)
17{
18 return a + b;
19}
20
21// this is function template
22// function template instantiate template functions.
23template<typename T>
24T pro(T a, T b) noexcept
25{
26 return a * b;
27}
28
30{
32
33 stream << "sum is marked with noexcept: "
34 << is_noexcept_v<sum, int, int> << tpf::endl;
35
36 stream << "summation is marked with noexcept: "
37 << is_noexcept_v<summation, int, int> << tpf::endl;
38
39 stream << "pro<int> is marked with noexcept: "
40 << is_noexcept_v<pro<int>, int, int> << tpf::endl;
41
42 // pro_int is a template function,
43 // or an instance of the function template
44 auto pro_int = pro<int>;
45
46 // it does not compile at all.
47 // stream << "pro_int is marked with noexcept: "
48 // << is_noexcept_v<pro_int, int, int> << tpf::endl;
49
50 // constexpr means the expression is compile-time expression
51 constexpr auto cpro_int = pro<int>;
52
53 stream << "cpro_int is marked with noexcept: "
54 << is_noexcept_v<cpro_int, int, int> << tpf::endl;
55
56 /*
57 pro is a function template that instantiate or generate
58 template functions.
59
60 pro<int> is not a function template,
61 but a template function, or
62 a specialization of the function template,
63 an instance of the function template.
64
65 So, a function template and a template function are totally
66 different entities.
67 */
68
69}
70
71int main()
72{
74}
int summation(int a, int b)
T pro(T a, T b) noexcept
void examples_for_is_noexcept()
int main()
constexpr auto is_noexcept_v
int sum(int a, int b) noexcept
tpf::sstream stream
constexpr auto endl
Definition: tpf_output.hpp:973
Stream output operators << are implemented.