Могу ли я различить эти типы в шаблоне, чтобы я мог определить указатель, когда объект в std :: evect std :: shared_ptr и не делайте этого, если тип не является std :: shared_ptr? < /p>
Вот код: < /p>
Код: Выделить всё
#include
#include
struct S {
void member() const {}
};
void fn(const auto& arr) {
for (const auto& val : arr) {
// This won't compile with call fn(objects) below
const S& obj = *val;
// I want to have something like (I understand that I mix different things, I just want to show the idea)
const auto& obj = std::is_same ? (*val) : val;
// Or even better
const S& obj = std::is_same ? (*val) : val;
obj.member();
}
}
int main()
{
std::vector objects;
std::vector pointers;
// I want make fn transparent for use containers of types T and std::shared_ptr
fn(objects);
fn(pointers);
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... shared-ptr