65 std::unique_ptr<int> ub)
71 std::shared_ptr<int> sb)
78 std::unique_ptr<int> ua{ra};
79 std::unique_ptr<int> ub{rb};
87 std::unique_ptr<int>& ub)
99 auto call_by_value_sum = std::async(&sld::call_by_value_sum, 1, 2);
108 auto call_by_const_reference_value_sum =
109 std::async(&sld::call_by_const_reference_value_sum, std::cref(n), std::cref(m));
125 auto call_by_reference_sum =
130 stream <<
"call_by_value_sum with 1, 2: "
133 stream <<
"call_by_const_reference_value_sum with 4, 5: "
134 << call_by_const_reference_value_sum.get() <<
tpf::endl;
136 stream <<
"call_by_reference_sum with 4, 5: "
137 << call_by_reference_sum.get() <<
tpf::endl;
139 auto call_by_pointer = std::async( &sld::call_by_pointer, &n, &m);
141 std::unique_ptr<int> ua{
new int{12}};
142 std::unique_ptr<int> ub{
new int{6}};
144 auto call_by_unique_ptr = std::async(&sld::call_by_unique_ptr,
145 std::move(ua), std::move(ub));
147 std::shared_ptr<int> sa{
new int{12}};
148 std::shared_ptr<int> sb{
new int{6}};
150 auto call_by_shared_ptr =
151 std::async(&sld::call_by_shared_ptr, std::move(sa), std::move(sb));
153 stream <<
"call_by_pointer with 4, 5: "
156 stream <<
"call_by_unique_ptr with 12, 6: "
157 << call_by_unique_ptr.get() <<
tpf::endl;
173 stream <<
"call_by_shared_ptr with 12, 6: "
174 << call_by_shared_ptr.get() <<
tpf::endl;
194 auto passing_raw_pointer_the_better_way =
195 std::async( &sld::passing_raw_pointer_the_better_way,
new int{5},
new int{4});
197 stream <<
"passing_raw_pointer_the_better_way with 5, 4: "
198 << passing_raw_pointer_the_better_way.get() <<
tpf::endl;
201 std::unique_ptr<int> uua{
new int{5} };
202 std::unique_ptr<int> uub{
new int{4} };
204 auto passing_unique_ptr_by_reference =
205 std::async( &sld::passing_unique_ptr_by_reference,
std::ref(uua),
std::ref(uub));
207 stream <<
"passing_unique_ptr_by_reference with 12, 6: "
208 << passing_unique_ptr_by_reference.get() <<
tpf::endl;
219 stream <<
"*uua, *uub are still VALID operation: " << (*uua + *uub) <<
tpf::endl;
221 catch(
const std::exception& e)
void examples_for_passing_parameters()
reference_wrapper< Type > ref(Type &val) noexcept
static return_t passing_unique_ptr_by_reference(std::unique_ptr< int > &ua, std::unique_ptr< int > &ub)
static return_t call_by_const_reference_value_sum(const int &a, const int &b)
static return_t call_by_reference_sum(int &a, int &b)
static return_t call_by_unique_ptr(std::unique_ptr< int > ua, std::unique_ptr< int > ub)
static return_t call_by_shared_ptr(std::shared_ptr< int > sa, std::shared_ptr< int > sb)
static return_t call_by_pointer(int *ap, int *bp)
static return_t call_by_value_sum(int a, int b)
static return_t passing_raw_pointer_the_better_way(int *ra, int *rb)
Stream output operators << are implemented.