0.2.0
Loading...
Searching...
No Matches
STL.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <fmt/format.h>
17#include <cstring>
18#include <string>
19#include <bitset>
20#include <functional>
21
22namespace NAV
23{
24
29template<typename T>
30std::string joinToString(const T& container, const char* delimiter = ", ", const std::string& elementFormat = "")
31{
32 std::string text;
33 std::for_each(container.begin(), container.end(), [&](const auto& element) {
34 text += fmt::format(fmt::runtime("{" + elementFormat + "}{}"), element, delimiter);
35 });
36 return text.substr(0, text.length() - strlen(delimiter));
37}
38
43template<typename T, typename U>
44std::string joinToStringCustom(const T& container, U&& formatFunc, const char* delimiter = ", ")
45{
46 std::string text;
47 std::for_each(container.begin(), container.end(), [&](const auto& element) {
48 text += fmt::format("{}{}", formatFunc(element), delimiter);
49 });
50 return text.substr(0, text.length() - strlen(delimiter));
51}
52
58template<std::size_t N>
59bool operator<(const std::bitset<N>& lhs, const std::bitset<N>& rhs)
60{
61 for (size_t i = N - 1;; i--)
62 {
63 if (lhs[i] ^ rhs[i]) { return rhs[i]; }
64 if (i == 0) { break; }
65 }
66 return false;
67}
68
69} // namespace NAV
std::string joinToString(const T &container, const char *delimiter=", ", const std::string &elementFormat="")
Joins the container to a string.
Definition STL.hpp:30
bool operator<(const std::bitset< N > &lhs, const std::bitset< N > &rhs)
Comparison operator for bitsets.
Definition STL.hpp:59
std::string joinToStringCustom(const T &container, U &&formatFunc, const char *delimiter=", ")
Joins the container to a string.
Definition STL.hpp:44