Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to port std::move to my kernel?

I'm concerned that in kernel land I will not have access to things like std::move, std::forward, std::initializer_list, etc. While some of these features are built into the language, they still require the appropriate headers and library implementation. Is the following sufficient to take advantage of move semantics, or do I need to go the full nine yards and port a C++ library?

template <typename T>
typename remove_reference<T>::type&& move(T&& arg)
{
  return static_cast<typename remove_reference<T>::type&&>(arg);
}
like image 326
Rigby Avatar asked Sep 12 '14 22:09

Rigby


1 Answers

That should do it, assuming no typos. The complete definition is given in the standard (two actually; old and new), and I've done exactly that: just copy the official version into my own header, and then address my special requirements and/or support old gnu std lib but compiler groks rvalue references.

To address @T.C.'s concern, it is still useful to be able to write my own move-only types and be able to use them e.g. return from functions, even if the supplied containers don't know about it. The Boost container classes do, and you can override the configuration to tell Boost you have &&, if you supply all the std::move, std::forward, and whatnot that it needs. I've also gotten a hybrid approach using native rvalue references and Boost move emulation working at the same time, for compatibility with code compiled with Boost as normally configured.

like image 143
JDługosz Avatar answered Oct 15 '22 20:10

JDługosz