Skip to content

Commit

Permalink
[brief] Code clean-up.
Browse files Browse the repository at this point in the history
[detailed]
- Removes headers that aren't used.
- Updates the macro implementation to use std::array over C-style
  arrays.
- Remove the universal references from the functors passed in to the
  string functions.
  • Loading branch information
marovira committed Sep 17, 2024
1 parent c8f11db commit 4b1527b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
7 changes: 0 additions & 7 deletions include/zeus/algorithm.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#pragma once

#include "assert.hpp"

#include <array>
#include <functional>
#include <numeric>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>

namespace zeus
{
Expand Down
22 changes: 15 additions & 7 deletions include/zeus/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "platform.hpp"

#include <array>
#include <source_location>
#include <string>

Expand All @@ -19,8 +20,10 @@ namespace zeus
} // namespace zeus

#if defined(ZEUS_BUILD_DEBUG)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
# define ASSERT(condition) \
zeus::assert_handler(condition, std::source_location::current(), #condition)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
# define ASSERT_MSG(condition, message) \
zeus::assert_handler(condition, std::source_location::current(), message)
#else
Expand All @@ -47,13 +50,18 @@ namespace zeus

# if defined(ZEUS_PLATFORM_WINDOWS)
static constexpr auto max_message_length{16 * 1'024};
char buffer[max_message_length];
memcpy(buffer, message.c_str(), message.size() + 1);
strncat_s(buffer, "\n", 3);
std::array<char, max_message_length> buffer{};
memcpy(buffer.data(), message.c_str(), message.size() + 1);
strncat_s(buffer.data(), buffer.size(), "\n", 3);

WCHAR wide_buffer[max_message_length] = {0};
MultiByteToWideChar(CP_UTF8, 0, buffer, -1, wide_buffer, sizeof(wide_buffer));
OutputDebugStringW(wide_buffer);
std::array<WCHAR, max_message_length> wide_buffer{};
MultiByteToWideChar(CP_UTF8,
0,
buffer.data(),
-1,
wide_buffer.data(),
static_cast<int>(wide_buffer.size() * sizeof(WCHAR)));
OutputDebugStringW(wide_buffer.data());
# endif
}

Expand Down Expand Up @@ -82,7 +90,7 @@ namespace zeus
# endif

# if defined(ZEUS_THROW_ASSERT)
throw std::runtime_error{message.c_str()};
throw std::runtime_error{assert_message.c_str()};
# else
std::abort();
# endif
Expand Down
3 changes: 1 addition & 2 deletions include/zeus/container_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "concepts.hpp"

#include <array>
#include <string>
#include <type_traits>
#include <vector>

namespace zeus
Expand Down
4 changes: 1 addition & 3 deletions include/zeus/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include "concepts.hpp"

#include <cmath>
#include <cstdlib>
#include <functional>
#include <algorithm>
#include <limits>

namespace zeus
Expand Down
2 changes: 0 additions & 2 deletions include/zeus/range.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#pragma once

#include "concepts.hpp"
#include "float.hpp"

#include <cmath>
#include <stdexcept>
#include <vector>

Expand Down
8 changes: 4 additions & 4 deletions include/zeus/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace zeus

template<DelimiterFunctor T>
constexpr std::vector<std::string>
split(std::string const& str, T&& is_delim, int max_split)
split(std::string const& str, T is_delim, int max_split)
{
if (str.empty())
{
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace zeus
}

template<DelimiterFunctor TrailingFun>
constexpr std::string rstrip(std::string const& str, TrailingFun&& is_trailing)
constexpr std::string rstrip(std::string const& str, TrailingFun is_trailing)
{
std::string ret{str};
ret.erase(std::find_if(ret.rbegin(),
Expand All @@ -101,7 +101,7 @@ namespace zeus
}

template<DelimiterFunctor LeadingFun>
constexpr std::string lstrip(std::string const& str, LeadingFun&& is_leading)
constexpr std::string lstrip(std::string const& str, LeadingFun is_leading)
{
std::string ret{str};
ret.erase(ret.begin(),
Expand All @@ -120,7 +120,7 @@ namespace zeus

template<DelimiterFunctor LeadingTrailingFun>
constexpr std::string strip(std::string const& str,
LeadingTrailingFun&& is_leading_trailing)
LeadingTrailingFun is_leading_trailing)
{
auto ret = lstrip(str, is_leading_trailing);
ret = rstrip(ret, is_leading_trailing);
Expand Down

0 comments on commit 4b1527b

Please sign in to comment.