MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
util.h File Reference
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <bit>
#include <iterator>
#include <queue>
#include <stack>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_map.h>
#include <absl/container/node_hash_set.h>
#include <fe/assert.h>
#include "mim/util/hash.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mim::unique_queue< Set >
struct  mim::GIDHash< T >
struct  mim::GIDLt< T >

Namespaces

namespace  mim

Typedefs

GID
template<class K, class V>
using mim::GIDMap = absl::flat_hash_map<K, V, GIDHash<K>>
template<class K>
using mim::GIDSet = absl::flat_hash_set<K, GIDHash<K>>
template<class K, class V>
using mim::GIDNodeMap = absl::node_hash_map<K, V, GIDHash<K>>
template<class K>
using mim::GIDNodeSet = absl::node_hash_set<K, GIDHash<K>>

Functions

Utility Functions
template<class D, class S>
requires (std::is_trivially_copyable_v<S> && std::is_trivially_copyable_v<D>)
constexpr D mim::bitcast_resize (const S &src) noexcept
 A bitcast from src of type S to D, supporting different sizes.
constexpr std::uint64_t mim::pad (std::uint64_t offset, std::uint64_t align) noexcept
Algorithms
template<class I, class T, class L>
constexpr I mim::binary_find (I begin, I end, T val, L lt) noexcept
constexpr std::string_view mim::subview (std::string_view s, size_t i, size_t n=std::string_view::npos) noexcept
 Like std::string::substr, but works on std::string_view instead.
void mim::find_and_replace (std::string &str, std::string_view what, std::string_view repl)
 Replaces all occurrences of what with repl.
Helpers for Containers
template<class S>
auto mim::pop (S &s) -> decltype(s.top(), typename S::value_type())
template<class Q>
auto mim::pop (Q &q) -> decltype(q.front(), typename Q::value_type())
template<class C, class K>
auto mim::lookup (const C &container, const K &key)
 Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr otherwise.
template<class C, class K>
auto mim::assert_lookup (C &container, const K &key)
 Looks up key in container, asserts that it exists, and returns the mapped value.
template<class C, class... Args>
auto mim::assert_emplace (C &container, Args &&... args)
 Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.