Skip to content

Commit

Permalink
refactor: Revisit noexcept specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Jan 4, 2025
1 parent 0e8b4f4 commit daca366
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 64 deletions.
2 changes: 1 addition & 1 deletion benchmark/core/tromino_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ auto dummy_callback(
{
}

auto main() noexcept -> int
auto main() -> int
{
ankerl::nanobench::Bench()

Expand Down
6 changes: 3 additions & 3 deletions include/tromino/gfx2d/step.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class Step final {
{
}

Step(Step const& other) noexcept = delete;
Step(Step const& other) = delete;

Step(Step&& other) noexcept = default;

~Step() noexcept = default;

Step& operator=(Step const& other) noexcept = delete;
Step& operator=(Step const& other) = delete;

Step& operator=(Step&& other) noexcept = delete;
Step& operator=(Step&& other) = delete;
};

} // namespace tromino::gfx2d
Expand Down
11 changes: 5 additions & 6 deletions include/tromino/gfx2d/view_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ namespace tromino::gfx2d {

class [[nodiscard]] TrominoBoardViewModel final {
public:
TrominoBoardViewModel() noexcept = delete;
TrominoBoardViewModel() = delete;

explicit TrominoBoardViewModel(::SDL_Window* window) noexcept;

TrominoBoardViewModel(TrominoBoardViewModel const&) noexcept = delete;
TrominoBoardViewModel(TrominoBoardViewModel const&) = delete;

TrominoBoardViewModel(TrominoBoardViewModel&&) noexcept = delete;
TrominoBoardViewModel(TrominoBoardViewModel&&) = delete;

~TrominoBoardViewModel() noexcept = default;

TrominoBoardViewModel& operator=(TrominoBoardViewModel const&) noexcept
= delete;
TrominoBoardViewModel& operator=(TrominoBoardViewModel const&) = delete;

TrominoBoardViewModel& operator=(TrominoBoardViewModel&&) noexcept = delete;
TrominoBoardViewModel& operator=(TrominoBoardViewModel&&) = delete;

void SetBoard(Board const& board, Style const& style) noexcept;

Expand Down
10 changes: 4 additions & 6 deletions include/tromino/gfx2d/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ namespace tromino::gfx2d {

class [[nodiscard]] Window final {
public:
Window() noexcept = delete;

explicit Window(
std::optional<std::string const> const& title, int width
) noexcept;

Window(Window const&) noexcept = delete;
Window(Window const&) = delete;

Window(Window&&) noexcept = delete;
Window(Window&&) = delete;

~Window() noexcept = default;

Window& operator=(Window const&) noexcept = delete;
Window& operator=(Window const&) = delete;

Window& operator=(Window&&) noexcept = delete;
Window& operator=(Window&&) = delete;

[[nodiscard]] ::SDL_Window* GetSdlWindow() const noexcept;

Expand Down
4 changes: 2 additions & 2 deletions src/cli/cli_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace tromino::cli {

void print_usage(std::ostream& os) noexcept
void print_usage(std::ostream& os)
{
// clang-format off
os <<
Expand All @@ -36,7 +36,7 @@ bool read_options(
char const* const* const argv,
options& options,
std::string& error
) noexcept
)
{
using std::string_literals::operator""s;

Expand Down
4 changes: 2 additions & 2 deletions src/cli/cli_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

namespace tromino::cli {

void print_usage(std::ostream& os) noexcept;
void print_usage(std::ostream& os);

bool read_options(
int argc, char const* const* argv, options& options, std::string& error
) noexcept;
);

} // namespace tromino::cli

Expand Down
4 changes: 2 additions & 2 deletions src/cli/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace tromino::cli::app {

void init(int const order, int const x, int const y) noexcept
void init(int const order, int const x, int const y)
{
auto const order_internal{static_cast<std::size_t>(order)};
std::size_t const size{order_internal * order_internal};
Expand All @@ -40,7 +40,7 @@ void init(
int const x,
int const y,
emulation_mode_type const emulation_mode
) noexcept
)
{
auto const order_internal{static_cast<std::size_t>(order)};
std::size_t const size{order_internal * order_internal};
Expand Down
4 changes: 2 additions & 2 deletions src/cli/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace tromino::cli::app {

void init(int order, int x, int y) noexcept;
void init(int order, int x, int y);

#ifdef _WIN64
void init(int order, int x, int y, emulation_mode_type emulation_mode) noexcept;
void init(int order, int x, int y, emulation_mode_type emulation_mode);
#endif // _WIN64

} // namespace tromino::cli::app
Expand Down
2 changes: 1 addition & 1 deletion src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "cli_options.hpp"
#include "init.hpp"

int main(int const argc, char const* const* const argv) noexcept
int main(int const argc, char const* const* const argv)
{
int exit_status{EXIT_FAILURE};
tromino::cli::options options{};
Expand Down
13 changes: 6 additions & 7 deletions src/cli/trmn_graph_vt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ constexpr char const BOTTOM_RIGHT{'\x6a'};

void add_tromino(
int pos_x, int pos_y, int flip_x, int flip_y, graph_state_t* graph_state
) noexcept;
);

void draw_board(board_t const& board, std::ostream& os) noexcept;
void draw_board(board_t const& board, std::ostream& os);

inline void init_board(board_t const& board) noexcept
{
Expand All @@ -78,13 +78,12 @@ inline void init_board(board_t const& board) noexcept
= MARK;
}

inline void
draw_at(int const x, int const y, char const c, std::ostream& os) noexcept
inline void draw_at(int const x, int const y, char const c, std::ostream& os)
{
os << CSI << y << ';' << x << 'H' << c;
}

void draw_board(board_t const& board, std::ostream& os) noexcept
void draw_board(board_t const& board, std::ostream& os)
{
int const order{board.order};
for (int i{0}; i < order; ++i)
Expand All @@ -103,7 +102,7 @@ void add_tromino(
int const flip_x,
int const flip_y,
graph_state_t* const graph_state
) noexcept
)
{
static constexpr std::chrono::milliseconds const DELAY_AFTER{68};

Expand Down Expand Up @@ -160,7 +159,7 @@ void add_tromino(

} // namespace

void use_vt(board_t& tromino_board, std::ostream& os) noexcept
void use_vt(board_t& tromino_board, std::ostream& os)
{
#ifdef _WIN64
::HANDLE const hStdout{::GetStdHandle(STD_OUTPUT_HANDLE)};
Expand Down
2 changes: 1 addition & 1 deletion src/cli/trmn_graph_vt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace tromino::cli::vt {

void use_vt(board_t& tromino_board, std::ostream& os) noexcept;
void use_vt(board_t& tromino_board, std::ostream& os);

} // namespace tromino::cli::vt

Expand Down
19 changes: 9 additions & 10 deletions src/cli/trmn_graph_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ constexpr char const top_right{'\xBB'};
constexpr char const bottom_left{'\xC8'};
constexpr char const bottom_right{'\xBC'};

void
add_tromino(int pos_x, int pos_y, int flip_x, int flip_y, void* state) noexcept;
void add_tromino(int pos_x, int pos_y, int flip_x, int flip_y, void* state);

void ensure_success(::BOOL is_success, std::string const& msg) noexcept;
void ensure_success(::BOOL is_success, std::string const& msg);

void draw_board(board_t const& board) noexcept;
void draw_board(board_t const& board);

inline void init_board(board_t const& board) noexcept
{
Expand All @@ -47,13 +46,13 @@ inline void init_board(board_t const& board) noexcept
= mark;
}

inline void draw_at(int const x, int const y, char const c) noexcept
inline void draw_at(int const x, int const y, char const c)
{
std::cout << c;
}

inline void
draw_at(int const x, int const y, char const c, ::HANDLE const hOutput) noexcept
draw_at(int const x, int const y, char const c, ::HANDLE const hOutput)
{
::COORD const coord{
.X{static_cast<::SHORT>(x)},
Expand All @@ -65,7 +64,7 @@ draw_at(int const x, int const y, char const c, ::HANDLE const hOutput) noexcept
draw_at(x, y, c);
}

void ensure_success(::BOOL const is_success, std::string const& msg) noexcept
void ensure_success(::BOOL const is_success, std::string const& msg)
{
if (!is_success)
{
Expand All @@ -81,7 +80,7 @@ void ensure_success(::BOOL const is_success, std::string const& msg) noexcept
}
}

void draw_board(board_t const& board) noexcept
void draw_board(board_t const& board)
{
int const order{board.order};
for (int i{0}; i < order; ++i)
Expand All @@ -101,7 +100,7 @@ void add_tromino(
int const flip_x,
int const flip_y,
void* const state
) noexcept
)
{
static constexpr std::chrono::milliseconds const DELAY_AFTER{68};

Expand Down Expand Up @@ -154,7 +153,7 @@ void add_tromino(

} // namespace

void use_wch(board_t& tromino_board, std::ostream& os) noexcept
void use_wch(board_t& tromino_board, std::ostream& os)
{
::SetConsoleTitle(TEXT("Tromino Puzzle"));

Expand Down
2 changes: 1 addition & 1 deletion src/cli/trmn_graph_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace tromino::cli::windows {

void use_wch(board_t& tromino_board, std::ostream& os) noexcept;
void use_wch(board_t& tromino_board, std::ostream& os);

} // namespace tromino::cli::windows

Expand Down
2 changes: 1 addition & 1 deletion src/cli/wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

template <typename T>
using tromino_cb_t
= void (*)(int pos_x, int pos_y, int flip_x, int flip_y, T* state) noexcept;
= void (*)(int pos_x, int pos_y, int flip_x, int flip_y, T* state);

template <typename T>
struct SolverState final {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/cli_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace tromino::tromino2d {

void print_usage(std::ostream& os) noexcept
void print_usage(std::ostream& os)
{
// clang-format off
os <<
Expand All @@ -30,7 +30,7 @@ bool read_options(
std::span<char const* const> const args,
options& options,
std::string& error
) noexcept
)
{
using std::string_literals::operator""s;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/cli_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

namespace tromino::tromino2d {

void print_usage(std::ostream& os) noexcept;
void print_usage(std::ostream& os);

bool read_options(
std::span<char const* const> args, options& options, std::string& error
) noexcept;
);

} // namespace tromino::tromino2d

Expand Down
4 changes: 2 additions & 2 deletions src/gui/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ inline void start_game_loop(
SharedState const& shared_state,
int const width,
std::optional<std::string const> const& title
) noexcept
)
{
static constexpr int const FRAME_DELAY{68};

Expand Down Expand Up @@ -157,7 +157,7 @@ int init(
tromino::gfx2d::Board const& board,
int const width,
std::optional<std::string const> const& title
) noexcept
)
{
auto const board_order{static_cast<std::size_t>(board.order)};
std::size_t const num_steps{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int init(
tromino::gfx2d::Board const& board,
int width,
std::optional<std::string const> const& title
) noexcept;
);

} // namespace tromino::tromino2d

Expand Down
2 changes: 1 addition & 1 deletion src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "init.hpp"
#include "params.hpp"

auto main(int const argc, char const* const* const argv) noexcept -> int
auto main(int const argc, char const* const* const argv) -> int
{
int exit_status{EXIT_FAILURE};
tromino::tromino2d::options options{};
Expand Down
9 changes: 4 additions & 5 deletions src/wasm/trmn/trmn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void add_tromino(
steps_->emplace_back(pos_x, pos_y, flip_x, flip_y);
}

void init(int const width) noexcept
void init(int const width)
{
steps = std::make_unique<std::vector<tromino::gfx2d::Step>>();

Expand Down Expand Up @@ -81,7 +81,7 @@ void render_frame() noexcept
viewModel->Render(*steps);
}

void start(tromino::gfx2d::Board const& board, int const width) noexcept
void start(tromino::gfx2d::Board const& board, int const width)
{
static constexpr int const SWAP_INTERVAL{4};

Expand Down Expand Up @@ -146,9 +146,8 @@ void start(tromino::gfx2d::Board const& board, int const width) noexcept

} // namespace

EMSCRIPTEN_KEEPALIVE extern "C" void playTromino(
int const order, int const markX, int const markY, int const width
) noexcept
EMSCRIPTEN_KEEPALIVE extern "C" void
playTromino(int const order, int const markX, int const markY, int const width)
{
std::size_t const order_internal{static_cast<std::size_t>(order)};
std::size_t const size{order_internal * order_internal};
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/trmn/trmn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#include <emscripten.h>

EMSCRIPTEN_KEEPALIVE extern "C" void
playTromino(int order, int markX, int markY, int width) noexcept;
playTromino(int order, int markX, int markY, int width);

#endif // WASM_TRMN_TRMN_HPP_
Loading

0 comments on commit daca366

Please sign in to comment.