Files
spark/src/lib/utils/auto_init_shared_ptr.h
T

26 lines
559 B
C++

#pragma once
#include <memory>
namespace bts::utils {
/**
* Simple wrapper for shared_ptr that initializes the underlying data in the
* default constructor.
*/
template <typename T>
class auto_init_shared_ptr {
public:
auto_init_shared_ptr() : value_(std::make_shared<T>()) {}
std::shared_ptr<T> &value() { return value_; }
const std::shared_ptr<T> &value() const { return value_; }
T &operator*() { return *value_; }
const T &operator*() const { return *value_; }
private:
std::shared_ptr<T> value_;
};
} // namespace bts::utils