A parameterized class (i.e. template class / class template) is not a class?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • christopher diggins

    A parameterized class (i.e. template class / class template) is not a class?

    It appears that the following is not considered a class:

    template<typena me T>
    class C { };

    ?

    So officially is this considered: a class, a template, a class template, or
    a template class? I always thought of it as a parameterized class. What
    would the rationale be for not considering it as just a 'class'?

    --
    Christopher Diggins
    Object Oriented Template Library (OOTL)
    Explore the world of cryptocurrency with clear guides, unbiased exchange reviews, airdrop alerts, and web3 insights. Out Of The Loop delivers practical knowledge for beginners and pros. Stay ahead in the crypto space.



  • Pete Becker

    #2
    Re: A parameterized class (i.e. template class / class template)is not a class?

    christopher diggins wrote:[color=blue]
    > It appears that the following is not considered a class:
    >
    > template<typena me T>
    > class C { };
    >
    > ?
    >
    > So officially is this considered: a class, a template, a class template, or
    > a template class? I always thought of it as a parameterized class. What
    > would the rationale be for not considering it as just a 'class'?
    >[/color]

    It's not a class because you can't define objects of type C. It's a
    class template, because it defines a pattern for creating classes.
    C<int> is a class.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)

    Comment

    • Howard

      #3
      Re: A parameterized class (i.e. template class / class template) is not a class?


      "christophe r diggins" <cdiggins@video tron.ca> wrote in message
      news:CONde.4379 9$SI2.1069666@w agner.videotron .net...[color=blue]
      > It appears that the following is not considered a class:
      >[/color]

      By whom?
      [color=blue]
      > template<typena me T>
      > class C { };
      >
      > ?
      >
      > So officially is this considered: a class, a template, a class template,
      > or a template class? I always thought of it as a parameterized class. What
      > would the rationale be for not considering it as just a 'class'?
      >[/color]

      I see no such rationale.

      Obviously, it's a template. What type of template?... a class template (as
      opposed to, say, a function template), since it defines a class.

      Also obviously (to me), it's a class, since it defines a class. I don't
      know if it's correct terminology, but I often refer to it as a template
      class, as in "a class that is described by a template".

      But I believe that the "correct" terminology is "class template".

      Is this question because one poster suggested there was no string class in
      standard C++? If so, I'd ignore that statement and get on with things.
      It's probably irrelevant in the long run, as long as someone you're
      communicating with understands what you're trying to say.

      -Howard


      Comment

      • Howard

        #4
        Re: A parameterized class (i.e. template class / class template) is not a class?


        "Pete Becker" <petebecker@acm .org> wrote in message
        news:-MadneWk_N-CNurfRVn-pg@rcn.net...[color=blue]
        > christopher diggins wrote:[color=green]
        >> It appears that the following is not considered a class:
        >>
        >> template<typena me T>
        >> class C { };
        >>
        >> ?
        >>
        >> So officially is this considered: a class, a template, a class template,
        >> or a template class? I always thought of it as a parameterized class.
        >> What would the rationale be for not considering it as just a 'class'?
        >>[/color]
        >
        > It's not a class because you can't define objects of type C. It's a class
        > template, because it defines a pattern for creating classes. C<int> is a
        > class.
        >[/color]

        Good point. I agree, (and take back my remark that C itself is a class).

        -Howard


        Comment

        • Pete Becker

          #5
          Re: A parameterized class (i.e. template class / class template)is not a class?

          Howard wrote:[color=blue]
          >
          > Is this question because one poster suggested there was no string class in
          > standard C++?
          >[/color]

          Maybe, but that statement is wrong. There's the basic_string class
          template (which we've established is not a class <g>), and there's the
          typedef string, which is a class.

          --

          Pete Becker
          Dinkumware, Ltd. (http://www.dinkumware.com)

          Comment

          • Abecedarian

            #6
            Re: A parameterized class (i.e. template class / class template) is not a class?

            Pete Becker wrote:[color=blue]
            > Howard wrote:[color=green]
            > >
            > > Is this question because one poster suggested there was no string[/color][/color]
            class in[color=blue][color=green]
            > > standard C++?
            > >[/color]
            >
            > Maybe, but that statement is wrong. There's the basic_string class
            > template (which we've established is not a class <g>), and there's[/color]
            the[color=blue]
            > typedef string, which is a class.[/color]

            Let me add something to the confusion:[color=blue]
            >From the C++ Standard, 7.1.3 The typedef specifier: "A typedef-name is[/color]
            thus a synonym for another type. A typedef-name does not introduce a
            new type the way a class declaration (9.1) or enum declaration does."
            Also, an instantiated class template has different code generation
            rules (not all functions are created) and different lookup rules (e.g.
            dependent names) ...
            If it were not different it would be the same ;-)

            Abe

            Comment

            • Victor Bazarov

              #7
              Re: A parameterized class (i.e. template class / class template)is not a class?

              Abecedarian wrote:[color=blue]
              > Pete Becker wrote:
              >[color=green]
              >>Howard wrote:
              >>[color=darkred]
              >>>Is this question because one poster suggested there was no string[/color][/color]
              >
              > class in
              >[color=green][color=darkred]
              >>>standard C++?
              >>>[/color]
              >>
              >>Maybe, but that statement is wrong. There's the basic_string class
              >>template (which we've established is not a class <g>), and there's[/color]
              >
              > the
              >[color=green]
              >>typedef string, which is a class.[/color]
              >
              >
              > Let me add something to the confusion:[color=green]
              >>From the C++ Standard, 7.1.3 The typedef specifier: "A typedef-name is[/color]
              > thus a synonym for another type. A typedef-name does not introduce a
              > new type the way a class declaration (9.1) or enum declaration does."
              > Also, an instantiated class template[/color]

              What is "an instantiated class template"? You mean an instantiation of
              a class template?..
              [color=blue]
              > has different code generation
              > rules (not all functions are created) and different lookup rules (e.g.
              > dependent names) ...
              > If it were not different it would be the same ;-)[/color]

              I am not sure how this "adds to the confusion"? 'std::string' is merely
              a synonym for 'std::basic_str ing<char>'. The latter is a class. So is
              'string'. I am not sure what it has to do with code generation rules or
              the lookup rules. It's a class as far as classes are concerned in the
              "class template versus class" context.

              V

              Comment

              • Pete Becker

                #8
                Re: A parameterized class (i.e. template class / class template)is not a class?

                Abecedarian wrote:[color=blue]
                > Pete Becker wrote:
                >[color=green]
                >>Howard wrote:
                >>[color=darkred]
                >>>Is this question because one poster suggested there was no string[/color][/color]
                >
                > class in
                >[color=green][color=darkred]
                >>>standard C++?
                >>>[/color]
                >>
                >>Maybe, but that statement is wrong. There's the basic_string class
                >>template (which we've established is not a class <g>), and there's[/color]
                >
                > the
                >[color=green]
                >>typedef string, which is a class.[/color]
                >
                >
                > Let me add something to the confusion:[/color]

                No, please don't. <g> string is a typedef for basic_string<ch ar>, which
                is a class. Yes, the rules are somewhat different, but the point is that
                it names a type. Don't get carried away with fine-tuning terms so that
                they become hard to use.

                --

                Pete Becker
                Dinkumware, Ltd. (http://www.dinkumware.com)

                Comment

                • Abecedarian

                  #9
                  Re: A parameterized class (i.e. template class / class template) is not a class?

                  Pete Becker wrote:[color=blue]
                  > string is a typedef for basic_string<ch ar>, which
                  > is a class. Yes, the rules are somewhat different, but the point is[/color]
                  that[color=blue]
                  > it names a type. Don't get carried away with fine-tuning terms so[/color]
                  that[color=blue]
                  > they become hard to use.[/color]

                  One last wish since you are the right addressee. I'd appreciate if the
                  C++ Standard allowed a "real" string class alternatively to a typedef
                  std::basic_stri ng<char, ...> string "class". Usability would be
                  improved significantly at virtually no cost and 100% backward
                  compatibility.

                  Regards,
                  Abe

                  Comment

                  • Pete Becker

                    #10
                    Re: A parameterized class (i.e. template class / class template)is not a class?

                    Abecedarian wrote:[color=blue]
                    >
                    > One last wish since you are the right addressee. I'd appreciate if the
                    > C++ Standard allowed a "real" string class alternatively to a typedef
                    > std::basic_stri ng<char, ...> string "class". Usability would be
                    > improved significantly at virtually no cost and 100% backward
                    > compatibility.
                    >[/color]

                    How would a "real" string class differ from basic_string<ch ar>?

                    --

                    Pete Becker
                    Dinkumware, Ltd. (http://www.dinkumware.com)

                    Comment

                    • Abecedarian

                      #11
                      Re: A parameterized class (i.e. template class / class template) is not a class?

                      Pete Becker wrote:[color=blue]
                      > Abecedarian wrote:[color=green]
                      > >
                      > > One last wish since you are the right addressee. I'd appreciate if[/color][/color]
                      the[color=blue][color=green]
                      > > C++ Standard allowed a "real" string class alternatively to a[/color][/color]
                      typedef[color=blue][color=green]
                      > > std::basic_stri ng<char, ...> string "class". Usability would be
                      > > improved significantly at virtually no cost and 100% backward
                      > > compatibility.
                      > >[/color]
                      >
                      > How would a "real" string class differ from basic_string<ch ar>?[/color]

                      namespace std {
                      class string { /* interface as basic_string template */ };
                      }

                      This class would be much more convenient for the user than a template
                      with 3 parameters. The verbosity of error messages could be reduced to
                      a fraction of basic_string, even more when string is used as template
                      in other templates.

                      Regards,
                      Abe

                      Comment

                      • Victor Bazarov

                        #12
                        Re: A parameterized class (i.e. template class / class template)is not a class?

                        Abecedarian wrote:[color=blue]
                        > [..]
                        > namespace std {
                        > class string { /* interface as basic_string template */ };
                        > }
                        >
                        > This class would be much more convenient for the user than a template
                        > with 3 parameters. The verbosity of error messages could be reduced to
                        > a fraction of basic_string, even more when string is used as template
                        > in other templates.[/color]

                        This should be solved by the compiler implementors, not by making changes
                        to the library. A simple feature: if a typedef is in scope, use it when
                        emitting an error message or a warning instead of full template spec.

                        V

                        Comment

                        • Pete Becker

                          #13
                          Re: A parameterized class (i.e. template class / class template)is not a class?

                          Abecedarian wrote:
                          [color=blue]
                          >
                          > namespace std {
                          > class string { /* interface as basic_string template */ };
                          > }
                          >
                          > This class would be much more convenient for the user than a template
                          > with 3 parameters.[/color]

                          That's what std::string is. It's the name of a class.
                          [color=blue]
                          > The verbosity of error messages could be reduced to
                          > a fraction of basic_string, even more when string is used as template
                          > in other templates.
                          >[/color]

                          Okay, that's a legitimate problem. But we're not going to redesign
                          std::string for that. The real problem is far more extensive: Compiler
                          writers haven't yet figured out how to give good error messages for
                          templates. Avoiding templates won't solve this problem. The solution has
                          to come from compiler writers.

                          --

                          Pete Becker
                          Dinkumware, Ltd. (http://www.dinkumware.com)

                          Comment

                          • Abecedarian

                            #14
                            Re: A parameterized class (i.e. template class / class template) is not a class?

                            Pete Becker wrote:[color=blue]
                            > Abecedarian wrote:[color=green]
                            > > The verbosity of error messages could be reduced to
                            > > a fraction of basic_string, even more when string is used as[/color][/color]
                            template[color=blue][color=green]
                            > > in other templates.[/color]
                            >
                            > Okay, that's a legitimate problem. But we're not going to redesign
                            > std::string for that.[/color]

                            No redesign necessary, just 'translate' basic_string<ch ar, ...> to
                            class string. Of course, the basic_string template shall remain as it
                            is. Just the typedef shall be optional with a real string class
                            (actually 2 classes).
                            [color=blue]
                            > The real problem is far more extensive: Compiler
                            > writers haven't yet figured out how to give good error messages for
                            > templates.[/color]

                            They cannot. The problem is situated in the C++ 'template mechanism'.
                            [color=blue]
                            > Avoiding templates won't solve this problem.[/color]

                            Avoiding unnecessary templates for the most frequent use cases really
                            would mostly solve this problem

                            A.

                            Comment

                            • Pete Becker

                              #15
                              Re: A parameterized class (i.e. template class / class template)is not a class?

                              Abecedarian wrote:[color=blue]
                              >
                              > No redesign necessary, just 'translate' basic_string<ch ar, ...> to
                              > class string. Of course, the basic_string template shall remain as it
                              > is. Just the typedef shall be optional with a real string class
                              > (actually 2 classes).
                              >[/color]

                              That's just like writing the same function twice: it leads to
                              maintenance problems and inconsistencies .

                              --

                              Pete Becker
                              Dinkumware, Ltd. (http://www.dinkumware.com)

                              Comment

                              Working...