Template Argument inside the Argument of a Function Declaration

This is a discussion on Template Argument inside the Argument of a Function Declaration within the C++ Programming forums, part of the General Programming Boards category; Take a look at the bold region...It is wrong..but I would need something like that for the constructor..! Code: namespace ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498

    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    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%.

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    ...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 ...
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21