C++ boost::utility














































C++ boost::utility



Boost.Utility provide class boost::noncopyable , which is defined in boost/noncopyable/hpp. This class makes it impossible to copy (and move) objects.

Code:

#include <boost/noncopyable.hpp> #include <string> #include <utility> #include <iostream> struct animal : boost::noncopyable { std::string name; int legs; animal(std::string n, int l) : name{std::move(n)}, legs{l} {} }; void print(const animal &a) { std::cout << a.name << '\n'; std::cout << a.legs << '\n'; } int main() { animal a{"dog", 4}; print(a); }
Output: dog 4


Comments