12 #ifndef HAMMER_TOOLS_UTILS
13 #define HAMMER_TOOLS_UTILS
17 #include <unordered_map>
24 #include <boost/functional/hash.hpp>
28 #define UNUSED(x) ((void)(x))
38 template<
typename KeyType,
typename ValueType>
39 ValueType
getOrDefault(
const std::map<KeyType, ValueType>& data, KeyType key, ValueType fallback) {
40 auto it = data.find(key);
41 return (it == data.end()) ? fallback : it->second;
44 template <
typename KeyType,
typename ValueType>
45 ValueType
getOrDefault(
const std::unordered_map<KeyType, ValueType>& data, KeyType key, ValueType fallback) {
46 auto it = data.find(key);
47 return (it == data.end()) ? fallback : it->second;
50 template <
typename KeyType,
typename ValueType>
51 auto const&
getOrThrow(
const std::map<KeyType, ValueType>& data, KeyType key, std::exception error) {
52 auto it = data.find(key);
53 if(it == data.end()) {
59 template<
typename KeyType,
typename ValueType>
60 auto&
getOrThrow(std::map<KeyType, ValueType>& data, KeyType key, std::exception error) {
61 auto it = data.find(key);
62 if(it == data.end()) {
68 template <
typename _InputIterator,
typename _OutputIterator,
typename _UnaryOperation>
69 _OutputIterator
transform_n(_InputIterator __first,
size_t __n, _OutputIterator __result, _UnaryOperation __op) {
70 return std::generate_n(__result, __n, [&__first, &__op]() -> decltype(
auto) {
return __op(*__first++); });
94 std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
97 std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out,
", "));
103 template<
typename K,
typename V>
104 using UMap = std::unordered_map<K, V, boost::hash<K>>;
std::unordered_map< K, V, boost::hash< K >> UMap
auto const & getOrThrow(const std::map< KeyType, ValueType > &data, KeyType key, std::exception error)
reversion_wrapper< T > reverse_range(T &&iterable)
Hammer configuration definitions.
ValueType getOrDefault(const std::map< KeyType, ValueType > &data, KeyType key, ValueType fallback)
auto begin(reversion_wrapper< T > w)
_OutputIterator transform_n(_InputIterator __first, size_t __n, _OutputIterator __result, _UnaryOperation __op)
auto end(reversion_wrapper< T > w)