Thread: Template Argument inside the Argument of a Function Declaration

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Question Template Argument inside the Argument of a Function Declaration

    Take a look at the bold region...It is wrong..but I would need something like that for the constructor..!
    Code:
    namespace set_mm{
    template<class X>
    class set
    {
        public:
        std::vector<X> dat;
        void insert(X);
        void insert(set<X>);
    
        set<X>(std::array<X,int>); //haywire...would actually need an int :(
        //Other Constructors
        bool containp(X);  //p for lisp'y predicates..!
        bool subsetp(set<X>);
    };
    }
    The place where I put 'int' must contain a constant integer at compile time...
    But.. how would I make the constructor able to handle "std::array"s of many sizes ?.
    (I don't need the size to be decided at runtime...the program using the class would have to somehow pass it..)

    I am making a set class based on the mathematical concept of set...because std::set is falling short of some of the tasks..and I don't need any sort of searching or sorting ..so vectors instead of a btree.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Try
    Code:
       template<int value> set(std::array<X, value>);
    (note I haven't tested and am going on memory late at night - it may be necessary to thrown in the typename keyword as well).

    Also bear in mind that std::array is not supported in all libraries.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    ...may be necessary...
    Nah..this seems to be working nicely...(though problems may surface when actually implementing the functions after designing the class..).. Thank you very much... (making templates still seem alien to me!)

    Code:
    std::array is not supported in all libraries
    g++ only needed an extra flag for enabling the support for c++0x ...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah, Visual C++ and g++ supports C++11 features, but not all other libraries may.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with template data type argument
    By TriKri in forum C++ Programming
    Replies: 6
    Last Post: 07-12-2008, 11:21 AM
  2. template argument
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2008, 03:01 AM
  3. template function argument deduce
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2008, 08:56 PM
  4. Implicit template argument deduction for classes
    By drrngrvy in forum C++ Programming
    Replies: 12
    Last Post: 03-30-2007, 05:31 PM
  5. Template function as argument
    By xErath in forum C++ Programming
    Replies: 9
    Last Post: 10-03-2004, 09:38 PM