FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

c++ template in D

 
Post new topic   Reply to topic     Forum Index -> Bindings
View previous topic :: View next topic  
Author Message
flashdog



Joined: 10 Oct 2008
Posts: 15

PostPosted: Mon Nov 10, 2008 11:43 pm    Post subject: c++ template in D Reply with quote

Hello,
how can I make this:
Code:

/* File : example.h */

// Some template definitions

template<class T> T max(T a, T b) { return  a>b ? a : b; }

template<class T> class vector {
  T *v;
  int sz;
 public:
  vector(int _sz) {
    v = new T[_sz];
    sz = _sz;
  }
  T &get(int index) {
    return v[index];
  }
  void set(int index, T &val) {
    v[index] = val;
  }
};

avaible in D?

Best regards
Back to top
View user's profile Send private message
aliloko



Joined: 31 Jan 2008
Posts: 15

PostPosted: Tue Nov 11, 2008 8:25 am    Post subject: Reply with quote

I would write :

Code:


T max(T)(T a, T b)
{
    return  a>b ? a : b;
}

class Vector(T)
{
    private:
        T[] v;

    public:
        this(int sz)
        {
            v.length = sz;
        }

        void set(int index, T val)
        {
            v[index] = val;
        }

        T get(int index)
        {
            return v[index];
        }

}
Back to top
View user's profile Send private message
flashdog



Joined: 10 Oct 2008
Posts: 15

PostPosted: Wed Nov 12, 2008 12:40 am    Post subject: Reply with quote

Thank you for the code, but I meant more to make a binding to the c++ code so that I can use it under D and to rewrite it.

Is it possible to make a binding to the c++ code?
Back to top
View user's profile Send private message
flashdog



Joined: 10 Oct 2008
Posts: 15

PostPosted: Wed Nov 12, 2008 12:41 am    Post subject: Reply with quote

Thank you for the code, but I meant more to make a binding to the c++ code so that I can use it under D and no to rewrite it.

Is it possible to make a binding to the c++ code?
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Wed Nov 12, 2008 5:58 am    Post subject: Reply with quote

It is possible but only in D2 and it's quite limited.
Back to top
View user's profile Send private message
aliloko



Joined: 31 Jan 2008
Posts: 15

PostPosted: Wed Nov 12, 2008 11:14 am    Post subject: Reply with quote

flashdog wrote:
Thank you for the code, but I meant more to make a binding to the c++ code so that I can use it under D and to rewrite it.

Is it possible to make a binding to the c++ code?

Oops, it's a miss.
Back to top
View user's profile Send private message
aliloko



Joined: 31 Jan 2008
Posts: 15

PostPosted: Wed Nov 12, 2008 11:16 am    Post subject: Reply with quote

flashdog wrote:
Thank you for the code, but I meant more to make a binding to the c++ code so that I can use it under D and to rewrite it.

Oops, it was a miss.
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Wed Nov 12, 2008 2:49 pm    Post subject: Reply with quote

http://www.digitalmars.com/d/2.0/cpp_interface.html

Quote:

D templates have little in common with C++ templates, and it is very unlikely that any sort of reasonable method could be found to express C++ templates in a link-compatible way with D.

This means that the C++ STL, and C++ Boost, likely will never be accessible from D.
Back to top
View user's profile Send private message AIM Address
Trass3r



Joined: 29 Feb 2008
Posts: 66
Location: Germany

PostPosted: Thu Aug 12, 2010 7:57 am    Post subject: Reply with quote

clayasaurus already said it: no.
Templates aren't supported.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Bindings All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group