| USRP Hardware Driver and Device Manual Version: 4.10.0.0 UHD and USRP Manual |

Loading...
Searching...
No Matches
assert_has.ipp
Go to the documentation of this file.
1//
2// Copyright 2010-2011 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8#pragma once
9
10#include <uhd/exception.hpp>
11#include <uhd/utils/algorithm.hpp>
12#include <uhd/utils/cast.hpp>
13#include <boost/format.hpp>
14
15 namespace uhd {
16
17 template <typename T, typename Range>
18 UHD_INLINE void assert_has(const Range& range, const T& value, const std::string& what)
19{
20 if (uhd::has(range, value))
21 return;
22 std::string possible_values = "";
23 size_t i = 0;
24 for (const T& v : range) {
25 if (i++ > 0)
26 possible_values += ", ";
27 possible_values += uhd::cast::to_str(v);
28 }
29 throw uhd::assertion_error(
30 boost::str(boost::format("assertion failed:\n"
31 " %s is not a valid %s.\n"
32 " possible values are: [%s].\n")
33 % uhd::cast::to_str(value) % what % possible_values));
34}
35
36} // namespace uhd
algorithm.hpp
cast.hpp
UHD_INLINE
#define UHD_INLINE
Definition config.h:65
exception.hpp
uhd::cast::to_str
auto to_str(const T &val) -> std::enable_if_t< std::is_arithmetic_v< T > &&!std::is_floating_point_v< T > &&!std::is_same_v< T, int8_t > &&!std::is_same_v< T, uint8_t > &&!std::is_enum_v< T > &&!detail::has_to_string_method< T >::value, decltype(std::to_string(val))>
SFINAE-based template for integer types that std::to_string can handle.
Definition cast.hpp:167
uhd
Definition build_info.hpp:12
uhd::has
UHD_INLINE bool has(const Range &range, const T &value)
Definition algorithm.hpp:68
uhd::assert_has
void assert_has(const Range &range, const T &value, const std::string &what="unknown")
Definition assert_has.ipp:18
uhd::assertion_error
Definition exception.hpp:48