Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:21:45+00:00 2026-05-23T15:21:45+00:00

I’m trying to expose the following c++ function to python using boost.python: template <typename

  • 0

I’m trying to expose the following c++ function to python using boost.python:

template <typename genType> 
    genType refract(
        genType const & I, 
        genType const & N, 
        typename genType::value_type const & eta);

and what I got is this:

template<typename N>
    N reflect(N const & i, N const & n, typename N::value_type const & eta)
    {
        return glm::N refract(i,n,eta);
    }

BOOST_PYTHON_MODULE(foo)
{
    def("reflect", reflect<float>);
    def("reflect", reflect<double>);
}

and I have the following error when compiling:

error C2780: ‘void boost::python::def(const char *,F,const A1 &,const A2 &,const A3 &)’ : expects 5 arguments – 2 provided

How should I wrap it?

—–edit——

This works:

template<class T>
T floor(T x)
{
    return glm::core::function::common::floor(x);
}

BOOST_PYTHON_MODULE(busta)
{
def("floor", floor<double>);
def("floor", floor<float>);
}

from the reference, floor() definition is the folowing:

template< typename genType >
genType floor (genType const &x)

I can build this as a DLL, then import it in python and use floor() from there. Life feels so nice…but..

This won’t work, and I would like to understand why:

template<class genType >
genType reflect (genType i, genType n, genType eta)
{
    return glm::core::function::geometric::refract(i, n,eta);
}

BOOST_PYTHON_MODULE(busta)
{
def("reflect", reflect<float>);
}

refract() definition is on the top of this post.

the error I get now is this:

1>foo.cpp(37): error C2893: Failed to specialize function template 'genType glm::core::function::geometric::refract(const genType &,const genType &,const genType::value_type &)'
1>          With the following template arguments:
1>          'float'
1>          foo.cpp(60) : see reference to function template instantiation 'genType 
`anonymous-namespace'::reflect<float>(genType,genType,genType)' being compiled
1>          with
1>          [
1>              genType=float
1>          ]
1>
1>Build FAILED.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:21:45+00:00Added an answer on May 23, 2026 at 3:21 pm

    This is not the perfect answer since it requires abusing the type system and writing plenty of additional glue code.
    You could try defining a wrapper template to decorate your target type such that it would have the necessary typedefs to satisfy the calling function (reflect).

    This example demonstrates the failings of such an approach. Notice that this reflect function performs a simple addition; however, for C++ to recognize the operator+ for the templated type N, the wrapper must explicitly define it.

    #include <iostream>   
    using namespace std;
    
    template<class N>
    N reflect(const N& n, const typename N::value_type& t)
    {
      return n + t;
    }
    
    template<class N>
    struct wrapper
    {
      typedef N value_type;
    
      wrapper(const N& n):_n(n){}
      operator N& () { return _n; }
      N operator+ (const N& r) const { return _n + r; }
    
      N _n;
    };
    
    int main(int,char**)
    {
      cout << reflect( wrapper<double>(1), 2.0) << endl;
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.