Code: Select all
#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);
}