USRP Hardware Driver and USRP Manual Version: 4.0.0.0-0-unknown
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
11#include <uhd/exception.hpp>
12#include <boost/format.hpp>
13#include <boost/lexical_cast.hpp>
14
15namespace uhd{
16
17 template<typename T, typename Range> UHD_INLINE void assert_has(
18 const Range &range,
19 const T &value,
20 const std::string &what
21 ){
22 if (uhd::has(range, value)) return;
23 std::string possible_values = "";
24 size_t i = 0;
25 for(const T &v : range){
26 if (i++ > 0) possible_values += ", ";
27 possible_values += boost::lexical_cast<std::string>(v);
28 }
29 throw uhd::assertion_error(str(boost::format(
30 "assertion failed:\n"
31 " %s is not a valid %s.\n"
32 " possible values are: [%s].\n"
33 )
34 % boost::lexical_cast<std::string>(value)
35 % what % possible_values
36 ));
37 }
38
39}//namespace uhd
#define UHD_INLINE
Definition config.h:52
Definition build_info.hpp:12
UHD_INLINE bool has(const Range &range, const T &value)
Definition algorithm.hpp:68
void assert_has(const Range &range, const T &value, const std::string &what="unknown")
Definition assert_has.ipp:17
Definition exception.hpp:49