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 12f4794..d3d0250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +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/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