From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/map.hxx | 176 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tiger-compiler/lib/misc/map.hxx (limited to 'tiger-compiler/lib/misc/map.hxx') diff --git a/tiger-compiler/lib/misc/map.hxx b/tiger-compiler/lib/misc/map.hxx new file mode 100644 index 0000000..fb429ac --- /dev/null +++ b/tiger-compiler/lib/misc/map.hxx @@ -0,0 +1,176 @@ +/** -*- C++ -*- + ** \file misc/map.hxx + ** \brief Implementation of misc::map. + */ + +#pragma once + +#include +#include + +#include + +#include +#include +#include + +namespace misc +{ + template map* map::clone() const + { + return new map(*this); + } + + template + typename map::const_iterator map::find(const T& t) const + { + return map_.find(t); + } + + template + typename map::iterator map::find(const T& t) + { + return map_.find(t); + } + + template + typename map::iterator map::xfind(const T& t) + { + if (auto&& ires = find(t); ires != map_.end()) + return ires; + else + throw std::range_error(std::string("map: no mapping for ") + + boost::lexical_cast(t)); + } + + template + typename map::const_iterator map::xfind(const T& t) const + { + if (const auto&& ires = find(t); ires != map_.end()) + return ires; + else + throw std::range_error(std::string("map: no mapping for ") + + boost::lexical_cast(t)); + } + + template + typename map::key_compare map::key_comp() const + { + return map_.key_comp(); + } + + template N map::operator()(const T& t) const + { + return xfind(t)->second; + } + + template + template + requires ConstIterableType + std::vector map::operator()(const Container& ts) const + { + std::vector res; + for (const T& t : ts) + res.emplace_back(operator()(t)); + return res; + } + + template + std::ostream& map::print(std::ostream& ostr) const + { + for (const value_type& p : *this) + ostr << p.first << " -> " << p.second << misc::iendl; + return ostr; + } + + template N map::operator[](const T& t) const + { + return operator()(t); + } + + template N& map::operator[](const T& t) + { + return map_[t]; + } + + template typename map::iterator map::begin() + { + return map_.begin(); + } + + template typename map::iterator map::end() + { + return map_.end(); + } + + template + typename map::const_iterator map::begin() const + { + return map_.begin(); + } + + template + typename map::const_iterator map::end() const + { + return map_.end(); + } + + template + typename map::iterator map::lower_bound(const T& k) + { + return map_.lower_bound(k); + } + + template + typename map::const_iterator map::lower_bound(const T& k) const + { + return map_.lower_bound(k); + } + + template + std::pair::iterator, bool> + map::insert(const std::pair& x) + { + return map_.insert(x); + } + + template void map::insert(const map& other) + { + map_.insert(other.begin(), other.end()); + } + + template + template + std::pair::iterator, bool> + map::emplace(Args&&... args) + { + return map_.emplace(std::forward(args)...); + } + + template bool map::empty() const + { + return map_.empty(); + } + + template size_t map::size() const + { + return map_.size(); + } + + template N map::take(const T& t) + { + auto ires = xfind(t); + N elt = ires->second; + map_.erase(ires); + return elt; + } + + template void map::clear() { map_.clear(); } + + template + std::ostream& operator<<(std::ostream& ostr, const map& m) + { + return m.print(ostr); + } + +} // namespace misc -- cgit v1.2.3