initlog();
{
+ deallog << "Part 1:" << std::endl;
+
Lazy<int> lazy_integer;
deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
<< std::endl;
deallog << "[initializing object]" << std::endl;
return 42;
});
- deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
+
+ // Lazy computes the result on a different task, which may be on a
+ // different thread. To avoid producing unreliable output, make
+ // sure we don't say
+ // deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
+ // but the following, where the order of computation and output are
+ // clear and well defined:
+ deallog << "lazy_integer.has_value() = " +
+ std::to_string(lazy_integer.has_value())
<< std::endl;
deallog << "lazy_integer.value() = " << lazy_integer.value() << std::endl;
return -1;
});
- deallog << "lazy_integer.value() = " << lazy_integer.value() << std::endl;
+ deallog << "lazy_integer.value() = " + std::to_string(lazy_integer.value())
+ << std::endl;
}
{
+ deallog << "Part 2:" << std::endl;
+
Lazy<int> lazy_integer;
- deallog << "lazy_integer.value() = "
- << lazy_integer.value_or_initialize([&]() {
- deallog << "... [initializing object] ... ";
- return 42;
- })
+ deallog << "lazy_integer.value() = " +
+ std::to_string(lazy_integer.value_or_initialize([&]() {
+ deallog << "... [initializing object] ... " << std::endl;
+ return 42;
+ }))
<< std::endl;
}
+DEAL::Part 1:
DEAL::lazy_integer.has_value() = 0
DEAL::[initializing object]
DEAL::lazy_integer.has_value() = 1
DEAL::lazy_integer.value() = 42
DEAL::lazy_integer.value() = 42
-DEAL::lazy_integer.value() = ... [initializing object] ... 42
+DEAL::Part 2:
+DEAL::... [initializing object] ...
+DEAL::lazy_integer.value() = 42
DEAL::OK!
deallog << "... [ reset ] ... " << std::endl;
lazy_integer_4.reset();
- deallog << "value_or_initialize: "
- << lazy_integer_4.value_or_initialize([&]() {
- deallog << "... [ initialized ] ... ";
- return 45;
- })
+ deallog << "value_or_initialize: " +
+ std::to_string(lazy_integer_4.value_or_initialize([&]() {
+ deallog << "... [ initialized ] ... " << std::endl;
+ return 45;
+ }))
<< std::endl;
deallog << "OK!" << std::endl;