Thread: adding to C++

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Question adding to C++

    how would you go about officially adding to the C++ language.

    for example...

    I am sure we all know about the select case function in BASIC. Now, C++ surpasses BASIC by far in all aspects, except for this one, I believe. And of course it is not essential, but it is nice.

    I'm sorry, but C++'s switch statement just pales compared to BASIC's powerful select case. The reason for that is because switch requires constant values, while select case does not.

    Now of course, there are ways you could build a library of your own to make some sort of make-shift select case for C++ if you wanted to, but would it not be possible to just go to ANSI and have the standard C++ switch statement changed to make it able to support things other than constants?

    I liked the ability in basic to be able to do things like:

    Code:
    SELECT CASE x
    CASE IS > 21 AND CASE IS < 35
    PRINT this
    CASE >= 35
    PRINT that
    CASE ELSE 
    PRINT the_other_thing
    END SELECT
    Now, of course you couldn't do that with the switch statement, it just is not possible, because it only accepts constants. Yes, you could do it using if statements, which is what we all do, but I just like the power of select case, and would like it to be equaled by C++'s switch.
    My Website

    "Circular logic is good because it is."

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I wouldn't try to change the langauge until I had a complete understanding of the current standard for the langauge, I would want to know what code the changes would potentially break, and generally have a very deep understanding of it before suggesting improvements. Reaching that level however, is probably more effort than it's worth.

    Having switch support just constants (and furthermore, not breaking by default), is an issue with speed. It enables the compiler to make optimizations.

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    how would you implement it into your compiler?

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    You have to send your suggestion
    to the ansi committe they have setup. I'm pretty sure they will
    only consider new features if there are implementations that
    have it and systems built using it.

  5. #5
    booyakasha
    Join Date
    Nov 2002
    Posts
    208

    Re: adding to C++

    switch( x >= 35 ? 2 : x > 21 ? 1 : 0 ){

    case 2: cout << this; break;
    case 1: cout << that; break;
    default: cout << the_other_thing;

    }


    or I would just do:


    cout << x >= 35 ? this : x > 21 : that : the_other_thing ;

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    there's a reason they have to be constant.
    Code:
    switch(val)
       {
       case 1:
          break;
       case 2:
          break;
       case 2:
          break;
       };
    does not compile because there should be only one case for 2. If it's not a constant then they cases could be set at run time which could produce this situation.

    if you want non constants there's a real simple C way to do it. It's called if-else if-else
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Yes, you could do it using if statements, which is what we all do, but I just like the power of select case, and would like it to be equaled by C++'s switch.
    Yes, most programmers would use if-statements. But is that weaker than select case?

    If you need code for the example you gave, one would use if-statements, in other cases one would use switch.

    In my opinion if-statements are very useful when it comes to ranges and switch is very useful when it comes to options.

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You have to submit a proposal to the standards comittee. That proposal must satisfy several different criteria. You can find out how to do this in a back issue of CUJ at www.cuj.com in matt austerns column.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic adding of Controls
    By WDT in forum C# Programming
    Replies: 5
    Last Post: 04-22-2009, 07:59 AM
  2. help with storing the last value of a loop and adding it?
    By colmustang in forum C Programming
    Replies: 4
    Last Post: 03-08-2008, 09:31 AM
  3. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 01:59 AM
  4. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  5. Java: Sorting and Adding a Row in Table
    By alphaoide in forum Tech Board
    Replies: 4
    Last Post: 08-12-2005, 08:22 PM