I have a piece of code that uses "unique_ptr", but the Arduino environment does now know about:
#include <memory>
So i went to C++ reference https://en.cppreference.com/w/cpp/memory/unique_ptr
Defined in header "memory"
template<
class T,
class Deleter = std::default_delete<T>
> class unique_ptr;
template <
class T,
class Deleter
> class unique_ptr<T[], Deleter>;
Figured that it doesn't take much to "implement".
My H file looks like this:
class state_deleter { // a deleter class with state
int count_;
public:
state_deleter() : count_(0) {}
template <class T>
void operator()(T* p) {
Serial.prinln("[deleted #");
delete p;
}
};
template <
class T,
class Deleter
> class unique_ptr<T[], Deleter>;
template <class T> class Circular_Buffer {
private:
unique_ptr<T[],state_deleter> buffer;
// i left non relevant code out
};
More info here: https://cplusplus.com/reference/memory/unique_ptr/ Manages the storage of a pointer, providing a limited garbage-collection facility, with little to no overhead over built-in pointers (depending on the deleter used). https://cplusplus.com/ref...nique_ptr/get_deleter/
So i added the above from CPP reference to the piece of code and by adding the "deleter", i removed error messages. But still one remains:
'unique_ptr' is not a class template
I have implemented pieces of code from CPP reference before if i don't had access to it or needed a slightly adapted version and it worked.
Can it be done?
What makes this a "template class" a smart pointer?
class T,
class Deleter
not much too see here in this class definition.