Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ jobs:
with:
submodules: recursive

- uses: actions/setup-python@v5
with:
python-version: 3.13
cache: 'pip'

- name: Install cppcheck
run: |
sudo apt update
sudo apt install -y cppcheck
pip install --break-system-packages cppcheck

- name: Run cppcheck
run: |
Expand Down Expand Up @@ -57,4 +61,4 @@ jobs:

- name: Install clang-tidy and dependencies
run: |
cpp_checks --dirs include --dirs test
cpp_checks --dirs include --dirs test
109 changes: 109 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Cppcheck",
"type": "shell",
"command": "cppcheck",
"args": [
"--enable=all",
"--enable=performance",
"--enable=style",
"--enable=information",
"--enable=portability",
"--error-exitcode=1",
"--suppressions-list=.cppcheck.suppress",
"--suppress=missingIncludeSystem",
"--inline-suppr",
"--inconclusive",
"--std=c++23",
"-I",
"include",
"include",
"test"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": {
"owner": "cppcheck",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error|style|performance|portability|information):\\s+(.*)\\s+\\[(\\w+)\\]$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
},
"group": "build",
"presentation": {
"reveal": "always",
"panel": "dedicated",
"clear": true
}
},
{
"label": "Clang-Tidy (cpp_checks)",
"type": "shell",
"command": "cpp_checks",
"args": [
"--dirs",
"include",
"--dirs",
"test"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": {
"owner": "clang-tidy",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)\\s+\\[([\\w,-]+)\\]$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
},
"group": "build",
"presentation": {
"reveal": "always",
"panel": "dedicated",
"clear": true
}
},
{
"label": "Static Analysis: All",
"dependsOn": [
"Cppcheck",
"Clang-Tidy (cpp_checks)"
],
"dependsOrder": "sequence",
"problemMatcher": [],
"group": "build"
},
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"all"
],
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
]
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

## Next Release

### Types

- add convenient template for creating strong types easily

### Type Traits

- Introduce new concept `HasToString`

<!-- insertion marker -->
## [0.1.5](https://github.com/repo/owner/releases/tag/0.1.5) - 2026-08-13

Expand Down
59 changes: 39 additions & 20 deletions include/mstd/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,45 @@
#define MSTD_ENUM(EnumName, Underlying, LIST) enum class EnumName : Underlying;
#endif

#define MSTD_ENUM_BITFLAG(EnumName, Underlying, LIST) \
MSTD_ENUM(EnumName, Underlying, LIST) \
\
inline EnumName operator|(EnumName lhs, EnumName rhs) \
{ \
return static_cast<EnumName>( \
static_cast<Underlying>(lhs) | static_cast<Underlying>(rhs) \
); \
} \
inline EnumName& operator|=(EnumName& lhs, EnumName rhs) \
{ \
lhs = lhs | rhs; \
return lhs; \
} \
\
inline EnumName operator&(EnumName lhs, EnumName rhs) \
{ \
return static_cast<EnumName>( \
static_cast<Underlying>(lhs) & static_cast<Underlying>(rhs) \
); \
#define MSTD_ENUM_BITFLAG(EnumName, Underlying, LIST) \
MSTD_ENUM(EnumName, Underlying, LIST) \
\
inline constexpr EnumName operator|(EnumName lhs, EnumName rhs) \
{ \
return static_cast<EnumName>( \
static_cast<Underlying>(lhs) | static_cast<Underlying>(rhs) \
); \
} \
inline constexpr EnumName& operator|=(EnumName& lhs, EnumName rhs) \
{ \
lhs = lhs | rhs; \
return lhs; \
} \
\
struct EnumName##FlagTest \
{ \
Underlying value; \
constexpr operator EnumName() const noexcept \
{ \
return static_cast<EnumName>(value); \
} \
\
constexpr explicit operator bool() const noexcept \
{ \
return value != Underlying{0}; \
} \
}; \
\
inline constexpr EnumName##FlagTest operator&(EnumName lhs, EnumName rhs) \
{ \
return EnumName##FlagTest{static_cast<Underlying>( \
static_cast<Underlying>(lhs) & static_cast<Underlying>(rhs) \
)}; \
} \
\
inline constexpr bool operator!(EnumName lhs) \
{ \
return !static_cast<Underlying>(lhs); \
}

#endif // __MSTD__ENUM_HPP__
3 changes: 2 additions & 1 deletion include/mstd/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
#include "type_traits/quantity_traits.hpp" // IWYU pragma: export
#include "type_traits/ranges_traits.hpp" // IWYU pragma: export
#include "type_traits/ratio_traits.hpp" // IWYU pragma: export
#include "type_traits/string.hpp" // IWYU pragma: export

#endif // __MSTD__TYPE_TRAITS_HPP__
#endif // __MSTD__TYPE_TRAITS_HPP__
44 changes: 44 additions & 0 deletions include/mstd/type_traits/string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*****************************************************************************
<GPL_HEADER>

mstd library
Copyright (C) 2025-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#ifndef __MSTD__TYPE_TRAITS__STRING_HPP__
#define __MSTD__TYPE_TRAITS__STRING_HPP__

#include <concepts>
#include <string>

namespace mstd
{
/**
* @brief Concept checking whether Tag::toString(const T&) is a valid
* expression that returns something convertible to std::string.
*
* @tparam Tag the tag type expected to provide a static toString member
* @tparam T the value type passed to Tag::toString
*/
template <typename Tag, typename T>
concept HasToString = requires(const T &value) {
{ Tag::toString(value) } -> std::convertible_to<std::string>;
};
} // namespace mstd

#endif // __MSTD__TYPE_TRAITS__STRING_HPP__
28 changes: 28 additions & 0 deletions include/mstd/types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*****************************************************************************
<GPL_HEADER>

mstd library
Copyright (C) 2025-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#ifndef __MSTD__TYPES_HPP__
#define __MSTD__TYPES_HPP__

#include "types/strong_type.hpp" // IWYU pragma: export

#endif // __MSTD__TYPES_HPP__
Loading
Loading