Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
StlContainerConversion.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19#include <unordered_map>
20#include <set>
21#include <vector>
22
23namespace shambase {
24
25 template<class T>
26 inline std::vector<T> vector_from_set(const std::set<T> &in) {
27 std::vector<T> ret{};
28 for (const T &t : in) {
29 ret.push_back(t);
30 }
31 return ret;
32 }
33
34 template<class T>
35 inline std::set<T> set_from_vector(const std::vector<T> &in) {
36 std::set<T> ret{};
37 for (const T &t : in) {
38 ret.insert(t);
39 }
40 return ret;
41 }
42
43 template<class K, class T>
44 inline std::vector<K> keys_from_map(const std::unordered_map<K, T> &in) {
45 std::vector<K> ret{};
46 for (const auto &[key, value] : in) {
47 ret.push_back(key);
48 }
49 return ret;
50 }
51
52} // namespace shambase
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.