Boost logo

Boost Users :

Subject: [Boost-users] Boost.Move template-function parameter
From: Luke J. West (ljw_at_[hidden])
Date: 2012-01-12 05:27:15

Hi. I'm trying to implement a template function that 'moves' it's
parameter. Here's a simple moveable class...

   struct my_class {
    my_class() {}
    my_class(BOOST_RV_REF(my_class)) {}

    my_class& operator=(BOOST_COPY_ASSIGN_REF(my_class) c) {return *this;}


And here is the function...

   template<typename T > void steal(BOOST_COPY_ASSIGN_REF(T) c) {}

so it works fine when I do this...

   int main() {
     my_class c;
     steal<my_class >(c);

but not when I do this...

   int main() {
     int c;
     steal<int >(c);

It's as if 'int' is not a movable type which of course it trivially
is. I read that Boost.Container classes are 'move aware' and I assume
boost::vector<int > works, so what am I doing wrong - how to write my
'steal' function capable of moving it's argument when it's moveable
class, but not breaking for primitives?


Luke (hopeful newbie!)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at