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

  • Home
  • SEARCH
  • 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 7017189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:52:56+00:00 2026-05-27T22:52:56+00:00

I’m lost with templates. I have this code in a header: void push(lua_State *,

  • 0

I’m lost with templates.

I have this code in a header:

void push(lua_State *, bool);
void push(lua_State *, int);
void push(lua_State *, long);
void push(lua_State *, unsigned long);
void push(lua_State *, lua_Number);
void push(lua_State *, lua_CFunction);
void push(lua_State *, const char *);
void push(lua_State *, const char *, std::size_t);
void push(lua_State *, const std::string &);

template<typename T>
void push(lua_State * L, const std::vector<T> & value)
{
    lua_newtable(L);
    std::size_t size = value.size();
    for(unsigned int i = 0; i < size; i++)
    {
        lua_pushinteger(L, i + 1);
        push(L, value[i]);
        lua_settable(L, -3);
    }
}

inline void push(lua_State *, boost::tuples::null_type){}
inline void push(lua_State *, boost::tuple<>){}

template<typename HT, typename TT>
void push(lua_State * L, const boost::tuples::cons<HT, TT> & value){
    push(L, value.get_head());
    push(L, value.get_tail());
}

//Declared but not defined. *Intentional* compile-time error if trying to push a Luaproxy (undefined reference). Use Lua stack reference instead
template<typename T>
void push(lua_State* l, Luaproxy<T>& value);

template<typename T>      //most generic version
void push(lua_State* l, T& value){
    Luaproxy<T>::new_c(l, value, false);
}

I expect to see the boost::tuples::cons version of push() called when as second argument is passed a result of boost::make_tuple(...). But I get errors at linking that show that such calls are resolved to the most generic version of push, that is push(lua_State* l, T& value).

The final result is that I must be able to do

mystruct example;
push(l, boost::make_tuple(3, 4, example))

and this must call in turn

void push(lua_State * L, const boost::tuples::cons<HT, TT> & value)  //tuple contains int, int, mystruct
void push(lua_State *, int)
void push(lua_State * L, const boost::tuples::cons<HT, TT> & value)  //my tuple contains int mystruct
void push(lua_State *, int)
void push(lua_State * L, const boost::tuples::cons<HT, TT> & value)  //my tuple contains mystruct
void push(lua_State* l, T& value)

If I delete the most general form of my push() functions, the rest of the code of my application, where it calls push() with a typle as argument is correctly resolved to the push(lua_State * L, const boost::tuples::cons<HT, TT> & value) version of the function. So, for some reason the most generic version has an higher priority, and that’s what I don’t want.

edit:
I’m trying to follow Anycorn’s suggestion, but I’m not very good at this. I’m leaving the boost::tuples::cons version as is, and i want to disable the generic version if the argument is derived from boost::tuples::cons:

template<typename T, typename HT, typename TT>
void push(lua_State* l, T& value, typename boost::disable_if<boost::is_base_of< boost::tuples::cons<HT, TT>, T>, T>::type* =0 ){
    Luaproxy<T>::new_c(l, value, false);
}

and it’s still considering the cons type for push(l, boost::make_tuple(mystruct))

[cut]
/home/pisto/sorgenti/hopmodv4/src/hopmod/lua/push_function.hpp:48:6: note: template void lua::push(lua_State*, lua::Luaproxy&)
/home/pisto/sorgenti/hopmodv4/src/hopmod/lua/push_function.hpp:51:6: note: template void lua::push(lua_State*, const T&, typename boost::disable_if, T>, T>::type*)
/home/pisto/sorgenti/hopmodv4/src/hopmod/lua/push_function.hpp:56:6: note: template void lua::push(lua_State*, const boost::tuples::cons&)

  • 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-27T22:52:56+00:00Added an answer on May 27, 2026 at 10:52 pm

    this

    template<> template<typename HT, typename TT>
    void push< boost::tuples::cons<HT, TT> >(lua_State * L, const boost::tuples::cons<HT, TT> & value){
        push(L, value.get_head());
        push(L, value.get_tail());
    }
    

    should be

    template<typename HT, typename TT>
    void (lua_State * L, const boost::tuple<HT, TT> & value){
        push(L, value.get_head());
        push(L, value.get_tail());
    }
    

    notice that make_tuple returns tuple, not cons.

    if i understood your question correctly

    update:

    tuple inherits from cons. what you must do is fail the generic template if argument isn’t derivative of cons and enable it otherwise.

    http://www.boost.org/doc/libs/1_48_0/libs/utility/enable_if.html

    http://www.boost.org/doc/libs/1_36_0/libs/type_traits/doc/html/boost_typetraits/reference/is_base_of.html

    alternatively you can specialize tuple template function and cast tuple to its base, cons

    update:

    seeing what you try to do you need a way to test a tuple:
    lets try this:

    template<class T>
    is_tuple : boost::mpl::false_ {};
    
    template<class T0, class T1, ...>
    struct is_tuple<tuple<T0, T1, ..> > : boost::mpl::true_ {};
    

    then write function to disable/enable depending on tuple AND a function to handle cons<H,T>. Tuple function must call cons function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.