// // Copyright 2010 Ettus Research LLC // #include #include #include #include #include #include #include #ifndef INCLUDED_USRP_UHD_UTILS_HPP #define INCLUDED_USRP_UHD_UTILS_HPP namespace usrp_uhd{ template //TODO template this better std::vector get_map_keys(const std::map &m){ std::vector v; std::pair p; BOOST_FOREACH(p, m){ v.push_back(p.first); } return v; } } //namespace usrp_uhd /*! * Useful templated functions and classes that I like to pretend are part of stl */ namespace std{ class assert_error : public std::logic_error{ public: explicit assert_error(const string& what_arg) : logic_error(what_arg){ /* NOP */ } }; #define ASSERT_THROW(_x) if (not (_x)) { \ throw std::assert_error("Assertion Failed: " + std::string(#_x)); \ } template T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){ T tmp = init; for ( ; first != last; ++first ){ tmp = fcn(tmp, *first); } return tmp; } template bool has(InputIterator first, InputIterator last, const T &elem){ return last != std::find(first, last, elem); } template T sum(const T &a, const T &b){ return a + b; } }//namespace std #endif /* INCLUDED_USRP_UHD_UTILS_HPP */