[C++-sig] template function

Luca Sbardella luca.sbardella at gmail.com
Wed Aug 29 09:39:40 CEST 2007


Ops,
Sorry disregards previous message...fat fingers...

I Hi,
I have a class template with a member function template as follow

template<class A, class B>
class test  {
public:

 ........  Some member functions

  template<class L>
  L keys() const  {
      L list;
      .....
      return L;
};


I created a function to export the template in the following way

template<class A, class B, class L>
void export_test(string name)  {

typedef test<A,B> etest;

class_<etest>(name.c_str())
   .....  Implemented all the member functions
   .def("keys",       &etest::keys<L>)     **** trying to implement the
member function template
;

}

and used the export_test class to export to python. For example

export_test<double,double>("test_real");

Everything works fine if I comment
.def("keys",       &etest::keys<L>)
in the export_test. All the member functions of test are available in
Python.

However if I insert the .def("keys",       &etest::keys<L>)  the code will
not compile!!!

Am I missing something?

Thanks Luca






On 29/08/2007, Luca Sbardella <luca.sbardella at gmail.com> wrote:
>
> Hi,
> I have a class template with a function template as follow
>
> template<class A, ...., class Z>
> class test  {
> public:
>         typedef D
>         key_type;
>         typedef T
>         data_type;
>         typedef keyvaluepair<D,T>
>         value_type;
>         typedef typename vector_composite<value_type>::container
>         container;
>         typedef typename container::iterator
>         iterator;
>         typedef typename container::const_iterator
>         const_iterator;
>
>         dataserie(){}
>         //
>         /// \brief search for a key_type
>         /// @return If the return value is not negative than it represents
> the index associated with the value_type d,
>         /// otherwise idx = -return-1 representes the index where the
> element would be inserted if added to the container.
>         qm_long               search(const key_type& key)       const;
>         /// \brief check whether the value_type d is available
>         bool                  contains(const key_type& key)       const
> {if(this->search(key)<0) return false; return true;}
>         /// \brief get the index associated with the key_type t
>         qm_Size               index(const key_type& t)        const;
>         /// @param Time in years @returns the index i such that grid[i] is
> closest to t
>         qm_Size               closestIndex(const key_type& t) const;
>         /// @param Time in years @return closest time on grid
>         const value_type&     closestValue(const key_type& t)  const {
> return this->get(this->closestIndex(t));}
>
>         /// \brief The Add method
>         /// This member function should be used to add new elements to the
> timeserie
>         /// @param d The date
>         /// @param value The value associated with d
>         void add(const key_type& key, const data_type& value =
> data_type());
>
>         template<class L>
>         L keys() const {
>             L list;
>             //for(const_iterator it = this->begin();it!=this->end();++it)
> list.append(it->key());
>             return list;
>         }
>
>         //template<class L>
>         //L values()  {return m_values.dataToList<L>();}
>     protected:
>         void insert(qm_Size pos, const value_type& kv) {
> this->vector().insert(this->vector().begin()+pos,kv);}
>     };
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070829/26344d7c/attachment.htm>


More information about the Cplusplus-sig mailing list