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
40 changes: 40 additions & 0 deletions .git_template/hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"__split_buffer": "cpp",
"__tree": "cpp",
"queue": "cpp",
"stack": "cpp"
"stack": "cpp",
"ranges": "cpp"
},
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

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

Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
26 changes: 26 additions & 0 deletions include/mstd/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cstddef> // IWYU pragma: keep
#include <optional> // IWYU pragma: keep
#include <span> // IWYU pragma: keep
#include <string> // IWYU pragma: keep
#include <string_view> // IWYU pragma: keep
#include <type_traits> // IWYU pragma: keep

Expand Down Expand Up @@ -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<EnumName> from_string( \
std::string_view s \
) \
Expand All @@ -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<EnumName>( \
static_cast<Underlying>(lhs) | static_cast<Underlying>(rhs) \
); \
} \
\
inline EnumName operator&(EnumName lhs, EnumName rhs) \
{ \
return static_cast<EnumName>( \
static_cast<Underlying>(lhs) & static_cast<Underlying>(rhs) \
); \
}

#endif // __MSTD__ENUM_HPP__
28 changes: 28 additions & 0 deletions include/mstd/string.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__STRING_HPP__
#define __MSTD__STRING_HPP__

#include "string/join.hpp" // IWYU pragma: export

#endif // __MSTD__STRING_HPP__
64 changes: 64 additions & 0 deletions include/mstd/string/join.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*****************************************************************************
<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__STRING__JOIN_HPP__
#define __MSTD__STRING__JOIN_HPP__

#include <ranges>
#include <string>

#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 <joinable_range R>
std::string join(R&& r, std::string_view delim)
{
auto joined = std::ranges::views::join_with(std::forward<R>(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 <joinable_range R>
std::string join(R&& r)
{
return join(std::forward<R>(r), "");
}

} // namespace mstd

#endif // __MSTD__STRING__JOIN_HPP__
1 change: 1 addition & 0 deletions include/mstd/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
43 changes: 43 additions & 0 deletions include/mstd/type_traits/ranges_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*****************************************************************************
<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__RANGES_TRAITS_HPP__
#define __MSTD__TYPE_TRAITS__RANGES_TRAITS_HPP__

#include <ranges>

namespace mstd
{
/**
* @brief concept for ranges that can be joined into a string with a
* delimiter
*
* @tparam Range
*/
template <typename Range>
concept joinable_range = std::ranges::input_range<Range> &&
std::convertible_to<
std::ranges::range_reference_t<Range>,
std::string_view>;
} // namespace mstd

#endif // __MSTD__TYPE_TRAITS__RANGES_TRAITS_HPP__
5 changes: 5 additions & 0 deletions scripts/init_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e

git config core.hooksPath .git_template/hooks
echo "Git hooks configured for this repository."