Interfacing with C++ std::shared_ptr and std::unique_ptr

Andre Pany andre at s-e-a-p.de
Wed Jun 10 06:43:24 UTC 2020


Hi,

I would like to interface with the library 
https://github.com/NTNU-IHB/FMI4cpp
and have following class definitions in the header file:

``` c++
namespace fmi4cpp {

     template<class ModelDescription>
     class fmu_base {

     public:

         const std::string guid() const {
             return get_model_description()->guid;
         }

         const std::string model_name() const {
             return get_model_description()->model_name;
         }

         virtual std::shared_ptr<const ModelDescription> 
get_model_description() const = 0;

     };

     template<class model_description, class cs_fmu, class me_fmu>
     class fmu_provider : public virtual 
fmu_base<model_description> {

     public:

         virtual bool supports_cs() const = 0;

         virtual bool supports_me() const = 0;

         virtual std::unique_ptr <cs_fmu> as_cs_fmu() const = 0;

         virtual std::unique_ptr <me_fmu> as_me_fmu() const = 0;

     };
```

While unique_ptr is already available in drunime library 
core.stdcpp.memory,
shared_ptr is missing. Does someone already have translated 
shared_ptr?

Also, the C++ classes make use of templates. Is it still possible 
to call these
classes from D?

Kind regards
Andre


More information about the Digitalmars-d-learn mailing list