forked from dealii/dealii
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add a test for Threads::InitializationCheck
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2005 - 2021 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
#include <deal.II/base/lazy.h> | ||
|
||
#include <iostream> | ||
|
||
#include "../tests.h" | ||
|
||
using namespace dealii; | ||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
{ | ||
Lazy<int> lazy_integer; | ||
|
||
deallog << "lazy_integer.has_value() = " << lazy_integer.has_value() | ||
<< std::endl; | ||
|
||
lazy_integer.initialize([&]() { | ||
deallog << "[initializing object]" << std::endl; | ||
return 42; | ||
}); | ||
deallog << "lazy_integer.has_value() = " << lazy_integer.has_value() << "\n" | ||
<< "lazy_integer.value() = " << lazy_integer.value() << std::endl; | ||
|
||
lazy_integer.initialize([&]() { | ||
deallog << "[initializing object] again... not good." << std::endl; | ||
return -1; | ||
}); | ||
|
||
deallog << "lazy_integer.has_value() = " << lazy_integer.has_value() << "\n" | ||
<< "lazy_integer.value() = " << lazy_integer.value() << std::endl; | ||
} | ||
|
||
{ | ||
Lazy<int> lazy_integer; | ||
|
||
deallog << "lazy_integer.value() = " | ||
<< lazy_integer.value_or_initialize([&]() { | ||
deallog << "... [initializing object] ... "; | ||
return 42; | ||
}) | ||
<< std::endl; | ||
} | ||
|
||
|
||
deallog << "OK!" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
DEAL::lazy_integer.has_value() = 0 | ||
DEAL::[initializing object] | ||
DEAL::lazy_integer.has_value() = 1 | ||
lazy_integer.value() = 42 | ||
DEAL::lazy_integer.has_value() = 1 | ||
lazy_integer.value() = 42 | ||
DEAL::lazy_integer.value() = ... [initializing object] ... 42 | ||
DEAL::OK! |