File tree Expand file tree Collapse file tree 7 files changed +42
-15
lines changed Expand file tree Collapse file tree 7 files changed +42
-15
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ std::enable_if_t<!has_print_to_v<T>> dump(T t) {
99
99
100
100
// Will work automatically for all classes matching the pattern
101
101
102
- #endif
102
+ #endif
103
103
104
104
// / Option 3: C++17 "if constexpr" ////////////////////////////////////////////
105
105
Original file line number Diff line number Diff line change @@ -22,6 +22,6 @@ int main() {
22
22
std::cout << sizeof (fun ()) << std::endl;
23
23
// also allowed -- also an unevaluated context
24
24
25
- // fun();
25
+ // fun();
26
26
// ^ this causes a linker error (used in evaluated context)
27
27
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ bool is_odd(int[1][N % 2 == 0 ? 1 : -1] = nullptr) {
13
13
14
14
int main () {
15
15
16
- // int x[-1];
16
+ // int x[-1];
17
17
// ^ this is a compiler error - we can't use a negative array length
18
18
19
19
std::cout << " is_odd<0>() : " << is_odd<0 >() << std::endl;
Original file line number Diff line number Diff line change 19
19
</ProjectConfiguration >
20
20
</ItemGroup >
21
21
<ItemGroup >
22
- <ClCompile Include =" 06_06_tuple_includes_prime .cpp" />
22
+ <ClCompile Include =" 06_10_crtp .cpp" />
23
23
</ItemGroup >
24
24
<PropertyGroup Label =" Globals" >
25
25
<VCProjectVersion >15.0</VCProjectVersion >
Original file line number Diff line number Diff line change 5
5
6
6
void replace_string_thread (std::string& target, std::mutex& target_mutex,
7
7
const std::string to_replace, const std::string replacement) {
8
- std::lock_guard<std::mutex> lock (target_mutex);
8
+ std::lock_guard lock (target_mutex);
9
9
// ^ in C++17 we can omit the template parameter (deduction guides)
10
+ // in earlier versions we need to explicitly write "<std::mutex>"
10
11
// lock_guard is a *scoped lock*
11
12
target.replace (target.find (to_replace), to_replace.size (), replacement);
12
13
}
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
#include < string>
3
3
#include < future>
4
+ #include < chrono>
4
5
5
6
#include < filesystem>
6
7
namespace fs = std::filesystem;
7
8
8
- // Note: needs to be linked with -lstdc++fs (in GCC)
9
+ // Note: needs to be linked with -lstdc++fs (in GCC 8.2)
10
+ // experimental in earlier compilers
9
11
10
12
int main () {
13
+ using namespace std ::chrono_literals;
11
14
12
15
auto largest_future = std::async ([]() {
13
16
// find largest file in working directory
14
17
decltype (fs::file_size (std::declval<fs::path>())) largest_size = 0 ;
15
18
fs::path largest;
16
- for (auto & p : fs::directory_iterator (" ." )) {
17
- auto path = p.path ();
18
- auto s = fs::file_size (path);
19
- if (s > largest_size) {
20
- largest_size = s;
21
- largest = path;
19
+ try {
20
+ for (auto & p : fs::recursive_directory_iterator (" R:/" )) {
21
+ if (p.is_regular_file ()) {
22
+ auto path = p.path ();
23
+ auto s = fs::file_size (path);
24
+ if (s > largest_size) {
25
+ largest_size = s;
26
+ largest = path;
27
+ }
28
+ }
22
29
}
23
30
}
31
+ // when dealing with files, getting an exception isn't unlikely
32
+ catch (std::exception& e) {
33
+ std::cerr << std::endl << " Exception: " << e.what () << std::endl;
34
+ }
24
35
return largest;
25
36
});
26
37
27
- std::cout << " Searching for largest file..." << std::endl ;
38
+ std::cout << " Searching for largest file..." ;
28
39
29
40
// ... other work / progress bar / etc
41
+ while (largest_future.wait_for (250ms) != std::future_status::ready) {
42
+ std::cout << " ." ;
43
+ }
30
44
31
- std::cout << " Largest file: " << largest_future.get () << std::endl;
45
+ std::cout << std::endl << " Largest file: " << largest_future.get (). generic_string () << std::endl;
32
46
}
Original file line number Diff line number Diff line change 19
19
</ProjectConfiguration >
20
20
</ItemGroup >
21
21
<ItemGroup >
22
- <ClCompile Include =" 07_10_eigen .cpp" />
22
+ <ClCompile Include =" 07_04_boost_format .cpp" />
23
23
</ItemGroup >
24
24
<PropertyGroup Label =" Globals" >
25
25
<VCProjectVersion >15.0</VCProjectVersion >
77
77
<RunCodeAnalysis >false</RunCodeAnalysis >
78
78
<EnableCppCoreCheck >true</EnableCppCoreCheck >
79
79
<IncludePath >D:\dev\eigen;$(IncludePath)</IncludePath >
80
+ <OutDir >$(TMP)\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir >
81
+ <IntDir >$(TMP)\$(ProjectName)\tmp\$(Platform)\$(Configuration)\</IntDir >
80
82
</PropertyGroup >
81
83
<PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
82
84
<CodeAnalysisRuleSet >NativeRecommendedRules.ruleset</CodeAnalysisRuleSet >
83
85
<RunCodeAnalysis >false</RunCodeAnalysis >
84
86
<EnableCppCoreCheck >true</EnableCppCoreCheck >
85
87
<IncludePath >D:\dev\eigen;$(IncludePath)</IncludePath >
88
+ <OutDir >$(TMP)\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir >
89
+ <IntDir >$(TMP)\$(ProjectName)\tmp\$(Platform)\$(Configuration)\</IntDir >
90
+ </PropertyGroup >
91
+ <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
92
+ <OutDir >$(TMP)\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir >
93
+ <IntDir >$(TMP)\$(ProjectName)\tmp\$(Platform)\$(Configuration)\</IntDir >
94
+ </PropertyGroup >
95
+ <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
96
+ <OutDir >$(TMP)\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir >
97
+ <IntDir >$(TMP)\$(ProjectName)\tmp\$(Platform)\$(Configuration)\</IntDir >
86
98
</PropertyGroup >
87
99
<ItemDefinitionGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
88
100
<ClCompile >
You can’t perform that action at this time.
0 commit comments