|
Boost Users : |
Subject: [Boost-users] [container / move] return a container of non-movables from a function in C++03
From: Adam Romanek (romanek.adam_at_[hidden])
Date: 2013-08-13 10:09:42
Hi,
I'd like to return a container of non-movables from a function in C++03
with no success.
here is a sample code that does not compile for me:
#include <boost/container/vector.hpp>
#include <boost/move/utility.hpp>
class non_copyable {
BOOST_MOVABLE_BUT_NOT_COPYABLE(non_copyable)
public:
non_copyable(){}
non_copyable(BOOST_RV_REF(non_copyable)) {}
non_copyable& operator=(BOOST_RV_REF(non_copyable)) { return *this; }
};
typedef boost::container::vector<non_copyable> nc_vector;
nc_vector create() {
return nc_vector();
}
int main () {
nc_vector v(create());
return 0;
}
The compiler says:
(...)
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:
error: passing âconst non_copyableâ as âthisâ argument of
ânon_copyable::operator boost::rv<non_copyable>&()â discards qualifiers
[-fpermissive]
(...)
See below for a full compiler output.
I use Boost v1.54 and gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.
Is it a bug?
Here is the full compiler output:
In file included from
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/allocator_traits.hpp:388:0,
from
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:28,
from
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:37,
from main.cpp:1:
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:
In static member function âstatic void
boost::container::allocator_traits<Alloc>::priv_construct_dispatch2(boost::false_type,
Alloc&, T*, const P0&) [with T = non_copyable, P0 = non_copyable, Alloc
= std::allocator<non_copyable>, boost::false_type =
boost::integral_constant<bool, false>]â:
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:
instantiated from âstatic void
boost::container::allocator_traits<Alloc>::priv_construct(boost::true_type,
Alloc&, T*, const P0&) [with T = non_copyable, P0 = non_copyable, Alloc
= std::allocator<non_copyable>, boost::true_type =
boost::integral_constant<bool, true>]â
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:
instantiated from âstatic void
boost::container::allocator_traits<Alloc>::construct(Alloc&, T*, const
P0&) [with T = non_copyable, P0 = non_copyable, Alloc =
std::allocator<non_copyable>]â
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:555:10:
instantiated from âtypename
boost::container::container_detail::disable_if_memcpy_copy_constructible<I,
F, F>::type boost::container::uninitialized_copy_alloc_n(A&, I, typename
std::iterator_traits<_II>::difference_type, F) [with A =
std::allocator<non_copyable>, I = non_copyable*, F = non_copyable*,
typename
boost::container::container_detail::disable_if_memcpy_copy_constructible<I,
F, F>::type = non_copyable*, typename
std::iterator_traits<_II>::difference_type = int]â
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:734:7:
instantiated from âboost::container::vector<T,
Allocator>::vector(const boost::container::vector<T, Allocator>&) [with
T = non_copyable, Allocator = std::allocator<non_copyable>,
boost::container::vector<T, Allocator> =
boost::container::vector<non_copyable>]â
main.cpp:16:20: instantiated from here
/home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1:
error: passing âconst non_copyableâ as âthisâ argument of
ânon_copyable::operator boost::rv<non_copyable>&()â discards qualifiers
[-fpermissive]
WBR,
Adam Romanek
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net