I have some types like the following:
struct Order_t;
using SpOrder_t = std::shared_ptr<Order_t>;
using CpOrder_t = std::shared_ptr<const Order_t>;
using SomeOrders_t = std::vector<SpOrder_t>;
using ConstOrders_t = std::vector<CpOrder_t>;
I want to directly assign from a SomeOrders_t to a ConstOrders_t, but the compiler said those are different types:
SomeOrders_t _cur_ords;
ConstOrders_t TradingOrders() {
return _cur_ords;
};
Is there a method to let me assign directly? Or do I have to use a loop and assign them one by one?
If
Tis a template with one type parameter, anduandvare different types, thenT<u>andT<v>are different (and unrelated) types.Even if there is an implicit conversion from
utov, there is no (default) implicit conversion fromT<u>toT<v>.(
std::shared_ptrhas converting constructors and assignments that enable the conversion fromshared_ptr<Order_t>toshared_ptr<const Order_t>, which makes them behave likeOrder_t*andconst Order_t*.)Making the conversion explicit is pretty trivial, though: