Re: C++0x syntax question

"Qian Ren" <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <OFDBDFB93A.08DE460C-ON0025819A.005038ED-4825819A.0052BAF4@notes.na.collabserv.com>
Hi Kelly,

According to the C++ standard (see below), the error messages are expected.
'typename' should be added.

  14.6 Name resolution

  2  A name used in a template declaration or definition and that is
     dependent on a template-parameter is assumed not to name a type
     unless the applicable name lookup finds a type name or the name
     is qualified by the keyword typename.

The diagnostic message from ILE C++ compiler with option LANGLVL
(*EXTENDED0X) is not as clear as the messages from g++ compiler.

We need more investigation on the reason why the compiler does not generate
diagnostic message without LANGLVL(*EXTENDED0X).

Thanks.


Qian Ren (Jarod)



From:	Kelly Beard <[email protected]>
To:	"Bare Metal Programming IBM i (AS/400 and iSeries)"
            <c400-l-Zwy7GipZuJhWk0Htik3J/[email protected]>
Date:	09/13/2017 12:06 AM
Subject:	Re: [C400-L] C++0x syntax question
Sent by:	"C400-L" <c400-l-bounces-Zwy7GipZuJhWk0Htik3J/[email protected]>



per my question, this does seem to be a change in syntax in the language.
 g++ is more clear and complete in it's error reporting.  For the newer
stuff, the word "typename" should appear appear in front of the offending
line.  The corrected code is:

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <unistd.h>

using namespace std;


template<typename T> vector<T> split(const T & str, const T & delimiters)
{
    vector<T> v;
    typename T::size_type start = 0;
    size_t pos = str.find_first_of(delimiters, start);
    while (pos != T::npos) {
        if (pos != start) { // ignore empty tokens
            v.push_back(str.substr(start, pos - start));
        }
        start = pos + 1;
        pos = str.find_first_of(delimiters, start);
    }
    if (start < str.length()) { // ignore trailing delimiter
        v.push_back(str.substr(start, pos - start));
    }
    return v;
}


int main(int argc, char* argv[])
{
    string str = "this,is,a,test, of whatever, like, ok.";
    vector<string> v = split<string>(str, ", ");
    for (int i = 0; i < v.size(); ++i) {
        cout << v[i] << endl;
    }
}


On Tue, Sep 12, 2017 at 10:38 AM, Kelly Beard <[email protected]>
wrote:

> Take away the *EXTENDED0X option and it compiles just fine.
>
> On Tue, Sep 12, 2017 at 10:21 AM, Mark S Waterbury <
> [email protected]> wrote:
>
>> Kelly,
>>
>> Did this code ever  compile on IBM i under previous versions of the IBM
>> ILE C++ compiler?
>>
>> IBM does not strictly follow the ANSI standards for either C or C++ ...
>>
>> You could also install the open-source GCC compiler and it would
probably
>> compile this code for you ... of course, the resulting object code would
>> run under PASE ...
>>
>> Mark
>>
>>
>> > On 9/12/2017 10:57 AM, Kelly Beard wrote:
>>
>>> I am attempting to compile the following code under the newer compiler
>>> under V7R3 and the LANGLVL *EXTENDED0X option enabled.  I am using the
>>> 5799PTL 'icc' compiler front-end to do this.  The command default for
>>> CRTCPPMOD has been altered to always have *EXTENDED0X on by default.  I
>>> am
>>> getting this:
>>>
>>> "testme.cpp", line 14.18: CZP0130 (30) "start" is not declared.
>>>
>>> The offending line looks like:
>>>
>>> T::size_type start = 0;
>>>
>>> So, is there a change to the C++11 syntax here?  Thanks in advance, as
>>> always.  Here is the test program.
>>>
>>> #include <iostream>
>>> #include <string>
>>> #include <sstream>
>>> #include <iomanip>
>>> #include <vector>
>>> #include <unistd.h>
>>>
>>> using namespace std;
>>>
>>>
>>> template<typename T> vector<T> split(const T & str, const T &
delimiters)
>>> {
>>>      vector<T> v;
>>>      T::size_type start = 0;
>>>      size_t pos = str.find_first_of(delimiters, start);
>>>      while (pos != T::npos) {
>>>          if (pos != start) { // ignore empty tokens
>>>              v.push_back(str.substr(start, pos - start));
>>>          }
>>>          start = pos + 1;
>>>          pos = str.find_first_of(delimiters, start);
>>>      }
>>>      if (start < str.length()) { // ignore trailing delimiter
>>>          v.push_back(str.substr(start, pos - start));
>>>      }
>>>      return v;
>>> }
>>>
>>>
>>> int main(int argc, char* argv[])
>>> {
>>>      string str = "this,is,a,test, of whatever, like, ok.";
>>>      vector<string> v = split<string>(str, ", ");
>>>      for (int i = 0; i < v.size(); ++i) {
>>>          cout << v[i] << endl;
>>>      }
>>> }
>>>
>>>
>>>
>> --
>> This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L)
>> mailing list
>> To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
>> To subscribe, unsubscribe, or change list options,
>> visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_c400-2Dl&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=JIx2A7y90zICNe9TsvZcxWsOjFqIaKyxAV_cUrqz-oE&m=MKnhao0-ats7XYFBrj2BjgLAidFzHJ7ePjN-QY7NGX0&s=kePhUIAbAqUzvQ6NyH-nhVE93rQHurYDgnGT24UA43o&e=

>> or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
>> Before posting, please take a moment to review the archives
>> at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_c400-2Dl&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=JIx2A7y90zICNe9TsvZcxWsOjFqIaKyxAV_cUrqz-oE&m=MKnhao0-ats7XYFBrj2BjgLAidFzHJ7ePjN-QY7NGX0&s=CF-UciCK2qh2uE8Vjt2UETRX7tz0apcTaarraSzDH2U&e=
 .
>>
>>
>
>
> --
> Kelly Beard
>



--
Kelly Beard
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L)
mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_c400-2Dl&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=JIx2A7y90zICNe9TsvZcxWsOjFqIaKyxAV_cUrqz-oE&m=MKnhao0-ats7XYFBrj2BjgLAidFzHJ7ePjN-QY7NGX0&s=kePhUIAbAqUzvQ6NyH-nhVE93rQHurYDgnGT24UA43o&e=

or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_c400-2Dl&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=JIx2A7y90zICNe9TsvZcxWsOjFqIaKyxAV_cUrqz-oE&m=MKnhao0-ats7XYFBrj2BjgLAidFzHJ7ePjN-QY7NGX0&s=CF-UciCK2qh2uE8Vjt2UETRX7tz0apcTaarraSzDH2U&e=
 .



-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/c400-l.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.