What do these <> mean

This is a discussion on What do these <> mean within the C++ Programming forums, part of the General Programming Boards category; There's this line of code Code: typedef data_t data_array_t<>; and I'm not sure the significance of <> Thanks!...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    245

    What do these <> mean

    There's this line of code

    Code:
    typedef data_t data_array_t<>;
    and I'm not sure the significance of <>

    Thanks!

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,620
    EDIT: Never mind, I don't know...
    Devoted my life to programming...

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    Assuming the code is actual valid, it is a `typedef' of a template class that has default values for every parameter. In that case, it is significant in that the code would be invalid without them.

    Soma

    Code:
    template <typename T = int> class test{};
    int main()
    {
        test<> t;
    }

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Assuming the code is actual valid..
    What would it mean if valid?
    If data_t is a templated class or function, then data_t<T> is a type, not data_t...What does it mean to typedef something which is not a type?
    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 !



  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I didn't feel like building a test case to test, but the only way I can think of that it is valid is:
    * data_t is a templated type with a default value, maybe the initial size of the array?
    * data_array_t is now a type that corresponds to data_t<>.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    245
    Quote Originally Posted by tabstop View Post
    I didn't feel like building a test case to test, but the only way I can think of that it is valid is:
    * data_t is a templated type with a default value, maybe the initial size of the array?
    * data_array_t is now a type that corresponds to data_t<>.
    Going through this a bit, I think that's what it is. Thank you!!

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,237
    Quote Originally Posted by dayalsoap View Post
    There's this line of code

    Code:
    typedef data_t data_array_t<>;
    and I'm not sure the significance of <>

    Thanks!
    Are you absolutely sure those aren't really square brackets instead? It has the advantage of making sense, whereas what you posted is gobbledegook


    Code:
    typedef data_t data_array_t[];
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    O_o

    What I meant was that my comments were assuming that the compiler you have is allowing some kind of extension to `typedef' a template. If the compiler tells you it is invalid, as it is according to the standard, then my comments aren't accurate.

    data_array_t is now a type that corresponds to data_t<>.
    The angle brackets are in the wrong place for such a `typedef'.

    typedef data_t data_array_t[];
    Unless the compiler allows the extension, that makes just as little sense without a size.

    Soma

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,237
    Quote Originally Posted by phantomotap View Post
    Unless the compiler allows the extension, that makes just as little sense without a size.
    I have no idea if it's standard or not, but I've seen it before, and VC10 and gcc both accept the following:

    Code:
    typedef int array[];
    
    // recursive array sum, demo only
    int foo(array x, int n)
    {
    	if (n == 0) return 0;
    	return x[0] + foo(x + 1, n - 1);
    }
    EDIT: gcc accepts it with "-ansi -pedantic" without warning
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    Ah, well, it is being treated exactly as if it had been `typedef' pointer in that context.

    Still, in the context, you are correct; it is perfectly valid, but still, to my mind at least, doesn't make sense.

    Soma

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    245
    Quote Originally Posted by brewbuck View Post
    Are you absolutely sure those aren't really square brackets instead? It has the advantage of making sense, whereas what you posted is gobbledegook


    Code:
    typedef data_t data_array_t[];
    I copy and pasted.

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    My guess is a compiler extension. The only other cases where the type wraps around an identifier like that are arrays and functions. But template types do not. But <> are a spare bracketing character in that context, and if a compiler vender wanted to have additional parameter to a type, outside the framework of templates, arrays, and functions, that would be one of the few ways that would be unambiguous.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

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