Skip to content

Commit 0bb9eba

Browse files
authored
Merge pull request #674 from ckormanyos/modernization
Modernize up to Chapter 3 in snippets
2 parents 3e7f2fc + fc0ced6 commit 0bb9eba

62 files changed

Lines changed: 663 additions & 666 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code_snippets/chapter01/chapter01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright Christopher Kormanyos 2023.
3+
# Copyright Christopher Kormanyos 2023 -2025.
44
# Distributed under the Boost Software License,
55
# Version 1.0. (See accompanying file LICENSE_1_0.txt
66
# or copy at http://www.boost.org/LICENSE_1_0.txt)

code_snippets/chapter01/chapter01_01-001_led_program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2023.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)

code_snippets/chapter01/chapter01_07-001_namespace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -19,7 +19,7 @@ namespace another_space
1919
constexpr int version = 3;
2020
}
2121

22-
int main()
22+
auto main() -> int
2323
{
2424
// 1
2525
std::cout << this_space::version << std::endl;

code_snippets/chapter01/chapter01_07-002_namespace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -14,10 +14,10 @@ using namespace std;
1414

1515
uint8_t my_u8; // No need for std:: with uint8_t
1616

17-
int main()
17+
auto main() -> int
1818
{
1919
my_u8 = UINT8_C(42);
2020

2121
// 42
22-
std::cout << unsigned(my_u8) << std::endl;
22+
std::cout << unsigned { my_u8 } << std::endl;
2323
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -11,21 +11,21 @@
1111

1212
void initialize() { std::cout << "initialization" << std::endl; }
1313

14-
void use_i(const int i) { std::cout << "i = " << i << std::endl; }
15-
void use_j(const int j) { std::cout << "j = " << j << std::endl; }
16-
void use_k(const int k) { std::cout << "k = " << k << std::endl; }
14+
auto use_i(const int i) -> void { std::cout << "i = " << i << std::endl; }
15+
auto use_j(const int j) -> void { std::cout << "j = " << j << std::endl; }
16+
auto use_k(const int k) -> void { std::cout << "k = " << k << std::endl; }
1717

18-
void do_something()
18+
auto do_something() -> void
1919
{
2020
// Initialize someting.
2121
initialize();
2222

2323
// Declare i when using it in use_i().
24-
const int i = 3;
24+
const int i { 3 };
2525
use_i(i);
2626

2727
// Declare j when using it in use_j().
28-
const int j = 7;
28+
const int j { 7 };
2929
use_j(j);
3030

3131
// Declare k in the scope of the for-loop.
@@ -35,7 +35,7 @@ void do_something()
3535
}
3636
}
3737

38-
int main()
38+
auto main() -> int
3939
{
4040
do_something();
4141
}

code_snippets/chapter03/chapter03_02-001_fixed_size_integer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -12,13 +12,13 @@
1212
#include <iostream>
1313

1414
// This has *exactly* 16-bits signed.
15-
constexpr std::int16_t value16 = INT16_C(0x7FFF);
15+
constexpr std::int16_t value16 { INT16_C(0x7FFF) };
1616

1717
// This has *at least* 32-bits unsigned.
18-
constexpr std::uint_least32_t value32 =
19-
UINT32_C(4'294'967'295);
18+
constexpr std::uint_least32_t value32
19+
{ UINT32_C(4'294'967'295) };
2020

21-
int main()
21+
auto main() -> int
2222
{
2323
std::cout << std::hex << std::showbase << value16 << std::endl;
2424

code_snippets/chapter03/chapter03_02-002_prime_number.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2023.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,9 +18,9 @@
1818
// Types like uint32_t and macros such as UINT32_C() are portable.
1919
// See also https://godbolt.org/z/3c38v3EY5
2020

21-
constexpr auto prime_664999 = static_cast<std::uint32_t>(UINT32_C(10'006'721));
21+
constexpr std::uint32_t prime_664999 { UINT32_C(10'006'721) };
2222

23-
int main()
23+
auto main() -> int
2424
{
2525
std::cout << prime_664999 << std::endl;
2626
}

code_snippets/chapter03/chapter03_02-002a_explore_prime_numbers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2023.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -22,7 +22,7 @@ namespace
2222
{
2323
template<typename unsigned_integral_type = std::uint32_t,
2424
const unsigned_integral_type maximum_value = static_cast<std::uint32_t>(UINT32_C(10006730))>
25-
void compute_primes_via_sieve(std::vector<unsigned_integral_type>& primes)
25+
auto compute_primes_via_sieve(std::vector<unsigned_integral_type>& primes) -> void
2626
{
2727
// Use a sieve algorithm to generate
2828
// a uint8 table of primes.
@@ -99,7 +99,7 @@ namespace
9999
}
100100
}
101101

102-
int main()
102+
auto main() -> int
103103
{
104104
using unsigned_integral_prime_type = std::uint32_t;
105105

code_snippets/chapter03/chapter03_03-001_bool_type.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -10,15 +10,15 @@
1010
#include <iomanip>
1111
#include <iostream>
1212

13-
bool valid() { return true; }
14-
bool login() { return true; }
13+
auto valid() -> bool { return true; }
14+
auto login() -> bool { return true; }
1515

16-
void start_session() { }
16+
auto start_session() -> void { }
1717

18-
void do_something()
18+
auto do_something() -> void
1919
{
2020
// This Boolean test yields true or false.
21-
const bool session_is_ok = (valid() && login());
21+
const bool session_is_ok { valid() && login() };
2222

2323
// This tests if (session_is_ok == true).
2424
if(session_is_ok)
@@ -31,7 +31,7 @@ void do_something()
3131
}
3232
}
3333

34-
int main()
34+
auto main() -> int
3535
{
3636
do_something();
3737
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2017 - 2018.
2+
// Copyright Christopher Kormanyos 2017 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -14,34 +14,34 @@
1414
namespace mcal
1515
{
1616
// The mcal initialization.
17-
void init();
17+
auto init() -> void;
1818

1919
// The general purpose timer stuff in the mcal.
2020
namespace gpt
2121
{
22-
void init() { std::cout << "in gpt::init()" << std::endl; }
22+
auto init() -> void { std::cout << "in gpt::init()" << std::endl; }
2323

24-
std::uint32_t get_time_elapsed() { return UINT32_C(0); }
24+
auto get_time_elapsed() -> std::uint32_t { return UINT32_C(0); }
2525
}
2626

2727
// The ADC stuff in the mcal.
2828
namespace adc
2929
{
30-
void init() { std::cout << "in adc::init()" << std::endl; }
30+
auto init() -> void { std::cout << "in adc::init()" << std::endl; }
3131

32-
std::uint16_t read_value(const unsigned) { return UINT16_C(0); }
32+
auto read_value(const unsigned) -> std::uint16_t { return UINT16_C(0); }
3333
}
3434
}
3535

3636
// Initialize the mcal.
3737
// Note the clean organization with namespaces.
38-
void mcal::init()
38+
auto mcal::init() -> void
3939
{
4040
mcal::gpt::init();
4141
mcal::adc::init();
4242
}
4343

44-
int main()
44+
auto main() -> int
4545
{
4646
mcal::init();
4747
}

0 commit comments

Comments
 (0)