diff --git a/.git_template/hooks/prepare-commit-msg b/.git_template/hooks/prepare-commit-msg new file mode 100755 index 0000000..d2973d8 --- /dev/null +++ b/.git_template/hooks/prepare-commit-msg @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +MSG_FILE="$1" +COMMIT_SOURCE="${2:-}" + +# Skip merge or amend commits +if [ "$COMMIT_SOURCE" = "merge" ] || [ "$COMMIT_SOURCE" = "commit" ]; then + exit 0 +fi + +# Extract branch name +BRANCH_NAME=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) + +# Extract ISSUE KEY (ABC-123) +ISSUE_KEY=$(printf "%s" "$BRANCH_NAME" | grep -oE '[A-Z]{2,}-[0-9]+' | head -n1) + +# If no issue key found → do nothing +if [ -z "$ISSUE_KEY" ]; then + exit 0 +fi + +# Skip fixup commits +if grep -q '^fixup!' "$MSG_FILE"; then + exit 0 +fi + +# Only prepend if not already present +FIRST_LINE=$(head -n1 "$MSG_FILE") +case "$FIRST_LINE" in +"$ISSUE_KEY"*) exit 0 ;; +esac + +# Prepend issue key +TMP_FILE=$(mktemp) +{ + echo "$ISSUE_KEY $FIRST_LINE" + tail -n +2 "$MSG_FILE" +} >"$TMP_FILE" + +mv "$TMP_FILE" "$MSG_FILE" diff --git a/.vscode/settings.json b/.vscode/settings.json index 3aabd6d..63f4e75 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,6 +114,7 @@ "__split_buffer": "cpp", "__tree": "cpp", "queue": "cpp", - "stack": "cpp" + "stack": "cpp", + "ranges": "cpp" }, } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0126e2b..d3d0250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. ## Next Release +### Enum + +- introduce `MSTD_ENUM_BITFLAG` for bitwise operations on enums + +### String + +- introduce new string library +- add `join` function to concatenate string_view like ranges with a delimiter + +### Type Traits + +- add concept `joinable_range` + ## [0.0.3](https://github.com/repo/owner/releases/tag/0.0.3) - 2026-02-08 diff --git a/CMakeLists.txt b/CMakeLists.txt index 59ab53c..9ec9b32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.20) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + project(mstd VERSION 0.1.0 LANGUAGES CXX @@ -19,7 +22,7 @@ target_include_directories(mstd target_compile_features(mstd INTERFACE - cxx_std_20 + cxx_std_23 ) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/include/mstd/enum.hpp b/include/mstd/enum.hpp index e2cb3c3..ba55f88 100644 --- a/include/mstd/enum.hpp +++ b/include/mstd/enum.hpp @@ -27,6 +27,7 @@ #include // IWYU pragma: keep #include // IWYU pragma: keep #include // IWYU pragma: keep +#include // IWYU pragma: keep #include // IWYU pragma: keep #include // IWYU pragma: keep @@ -84,6 +85,14 @@ return {}; \ } \ \ + static constexpr std::string toString(EnumName e) \ + { \ + for (std::size_t i = 0; i < size; ++i) \ + if (values[i] == e) \ + return std::string(names[i]); \ + return {}; \ + } \ + \ static constexpr std::optional from_string( \ std::string_view s \ ) \ @@ -110,4 +119,21 @@ \ static constexpr EnumName##Meta enum_meta(EnumName) { return {}; } +#define MSTD_ENUM_BITFLAG(EnumName, Underlying, LIST) \ + MSTD_ENUM(EnumName, Underlying, LIST) \ + \ + inline EnumName operator|(EnumName lhs, EnumName rhs) \ + { \ + return static_cast( \ + static_cast(lhs) | static_cast(rhs) \ + ); \ + } \ + \ + inline EnumName operator&(EnumName lhs, EnumName rhs) \ + { \ + return static_cast( \ + static_cast(lhs) & static_cast(rhs) \ + ); \ + } + #endif // __MSTD__ENUM_HPP__ \ No newline at end of file diff --git a/include/mstd/string.hpp b/include/mstd/string.hpp new file mode 100644 index 0000000..5f73a00 --- /dev/null +++ b/include/mstd/string.hpp @@ -0,0 +1,28 @@ +/***************************************************************************** + + + 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 . + + +******************************************************************************/ + +#ifndef __MSTD__STRING_HPP__ +#define __MSTD__STRING_HPP__ + +#include "string/join.hpp" // IWYU pragma: export + +#endif // __MSTD__STRING_HPP__ \ No newline at end of file diff --git a/include/mstd/string/join.hpp b/include/mstd/string/join.hpp new file mode 100644 index 0000000..30062ee --- /dev/null +++ b/include/mstd/string/join.hpp @@ -0,0 +1,64 @@ +/***************************************************************************** + + + 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 . + + +******************************************************************************/ + +#ifndef __MSTD__STRING__JOIN_HPP__ +#define __MSTD__STRING__JOIN_HPP__ + +#include +#include + +#include "mstd/type_traits/ranges_traits.hpp" + +namespace mstd +{ + /** + * @brief Join a range of strings into a single string with a delimiter + * + * @tparam R + * @param r + * @param delim + * @return std::string + */ + template + std::string join(R&& r, std::string_view delim) + { + auto joined = std::ranges::views::join_with(std::forward(r), delim); + + return {joined.begin(), joined.end()}; + } + + /** + * @brief overload of join that uses an empty string as delimiter + * + * @tparam R + * @param r + * @return std::string + */ + template + std::string join(R&& r) + { + return join(std::forward(r), ""); + } + +} // namespace mstd + +#endif // __MSTD__STRING__JOIN_HPP__ \ No newline at end of file diff --git a/include/mstd/type_traits.hpp b/include/mstd/type_traits.hpp index 4449fe5..dc30437 100644 --- a/include/mstd/type_traits.hpp +++ b/include/mstd/type_traits.hpp @@ -27,6 +27,7 @@ #include "type_traits/math_traits.hpp" // IWYU pragma: export #include "type_traits/pack_traits.hpp" // IWYU pragma: export #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 #endif // __MSTD__TYPE_TRAITS_HPP__ \ No newline at end of file diff --git a/include/mstd/type_traits/ranges_traits.hpp b/include/mstd/type_traits/ranges_traits.hpp new file mode 100644 index 0000000..75d3c2d --- /dev/null +++ b/include/mstd/type_traits/ranges_traits.hpp @@ -0,0 +1,43 @@ +/***************************************************************************** + + + 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 . + + +******************************************************************************/ + +#ifndef __MSTD__TYPE_TRAITS__RANGES_TRAITS_HPP__ +#define __MSTD__TYPE_TRAITS__RANGES_TRAITS_HPP__ + +#include + +namespace mstd +{ + /** + * @brief concept for ranges that can be joined into a string with a + * delimiter + * + * @tparam Range + */ + template + concept joinable_range = std::ranges::input_range && + std::convertible_to< + std::ranges::range_reference_t, + std::string_view>; +} // namespace mstd + +#endif // __MSTD__TYPE_TRAITS__RANGES_TRAITS_HPP__ \ No newline at end of file diff --git a/scripts/init_repo.sh b/scripts/init_repo.sh new file mode 100755 index 0000000..ce6acd4 --- /dev/null +++ b/scripts/init_repo.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e + +git config core.hooksPath .git_template/hooks +echo "Git hooks configured for this repository."