aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-11-01 14:48:06 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-04 09:57:49 -0800
commit0014f5ba2947448703c9ba0afb1c9f1084f1fc50 (patch)
treeebef31442fa49aaeee34426fdd244fa34a58b1bc /host/include
parentebb06c983a4d5e68ebf6d51c05eac95b9fcbbaba (diff)
downloaduhd-0014f5ba2947448703c9ba0afb1c9f1084f1fc50.tar.gz
uhd-0014f5ba2947448703c9ba0afb1c9f1084f1fc50.tar.bz2
uhd-0014f5ba2947448703c9ba0afb1c9f1084f1fc50.zip
uhd: dict: Add typecast operator to std::map<>
This will now allow calls like this: uhd::dict<k, v> d = /* ... */; auto m = static_cast<std::map<k, v>>(d);
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/types/dict.hpp5
-rw-r--r--host/include/uhd/types/dict.ipp10
2 files changed, 15 insertions, 0 deletions
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp
index 8b7a63c69..b5858d61c 100644
--- a/host/include/uhd/types/dict.hpp
+++ b/host/include/uhd/types/dict.hpp
@@ -10,6 +10,7 @@
#include <uhd/config.hpp>
#include <list>
+#include <map>
#include <vector>
namespace uhd {
@@ -138,6 +139,10 @@ public:
*/
void update(const dict<Key, Val>& new_dict, bool fail_on_conflict = true);
+ /*! Typecast operator to std::map<>
+ */
+ operator std::map<Key, Val>() const;
+
private:
typedef std::pair<Key, Val> pair_t;
std::list<pair_t> _map; // private container
diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp
index b172d17f1..5a5024fcc 100644
--- a/host/include/uhd/types/dict.ipp
+++ b/host/include/uhd/types/dict.ipp
@@ -157,6 +157,16 @@ namespace uhd{
}
}
+ template <typename Key, typename Val>
+ dict<Key, Val>::operator std::map<Key, Val>() const
+ {
+ std::map<Key, Val> new_map;
+ BOOST_FOREACH (const pair_t& p, _map) {
+ new_map[p.first] = p.second;
+ }
+ return new_map;
+ }
+
} //namespace uhd
#endif /* INCLUDED_UHD_TYPES_DICT_IPP */