diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-01-28 14:52:59 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-02-15 11:12:54 -0800 |
commit | ed97ce3242176f44704216581d23547c302a238c (patch) | |
tree | ac5f8589532e62e5b42aa14c77e36042a4b3fe27 /host | |
parent | 55c6222579a01efd55e7ade3938031f9d5d0bfbd (diff) | |
download | uhd-ed97ce3242176f44704216581d23547c302a238c.tar.gz uhd-ed97ce3242176f44704216581d23547c302a238c.tar.bz2 uhd-ed97ce3242176f44704216581d23547c302a238c.zip |
uhd: utils: Add noncopyable class
This is a replacement for boost::noncopyable. It has two
implementations with identical APIs, selectable by a macro. One
"implementation" is a renaming of the Boost version. The other is
simply implemented using C++11 features.
The motivation is that the location for boost::noncopyable has changed
over the range of Boost versions, thus, using boost::noncopyable is
difficult to maintain for a broad range of Boost versions.
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/noncopyable.hpp | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index 7f45df1d3..894a804c4 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -20,6 +20,7 @@ UHD_INSTALL(FILES log_add.hpp math.hpp msg_task.hpp + noncopyable.hpp paths.hpp pimpl.hpp platform.hpp diff --git a/host/include/uhd/utils/noncopyable.hpp b/host/include/uhd/utils/noncopyable.hpp new file mode 100644 index 000000000..0f480f6c3 --- /dev/null +++ b/host/include/uhd/utils/noncopyable.hpp @@ -0,0 +1,55 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP +#define INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP + +#ifdef UHD_AVOID_BOOST + +namespace uhd { + +/*! Non-copyable class + * + * This is a re-implementation of boost::noncopyable using C++11 features. + * Deriving a class from this one will disallow it being assigned or copied: + * + * ~~~~{.cpp} + * #include <uhdlib/utils/noncopyable.hpp> + * + * class C : uhd::noncopyable {}; + * + * C c1; + * C c2(c1); // Won't work + * C c3; + * c3 = c1; // Won't work + * ~~~~ + */ +class noncopyable +{ +public: + noncopyable() = default; + ~noncopyable() = default; + + noncopyable(const noncopyable&) = delete; + noncopyable& operator=(const noncopyable&) = delete; +}; + +} /* namespace uhd */ + +#else + +# if BOOST_VERSION >= 105600 +# include <boost/core/noncopyable.hpp> +# else +# include <boost/noncopyable.hpp> +# endif +namespace uhd { +typedef boost::noncopyable noncopyable; +} + +#endif + +#endif /* INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP */ |