Better Late Than never ???

Started by jcfuller, May 28, 2024, 02:26:58 PM

Previous topic - Next topic

Robert

Quote from: MrBcx on May 29, 2024, 09:29:09 AM
Robert ...

Apparently my late update yesterday was made after you updated the example in BCXHelp.

The updated line (below) in the RBFOR example is critical for a successful compile.

S1$ = e.path().string().c_str()    ' Be careful not to accidentally change case


The .string () is a case sensitive C++ keyword in this instance.

O.K. Thanks. Help revised and uploaded to

https://bcxbasiccoders.com/smf/index.php?topic=1066.msg5521#msg5521

MrBcx

#6
Robert ...

Apparently my late update yesterday was made after you updated the example in BCXHelp.

The updated line (below) in the RBFOR example is critical for a successful compile.

S1$ = e.path().string().c_str()    ' Be careful not to accidentally change case


The .string () is a case sensitive C++ keyword in this instance.

MrBcx

#5
Robert,

I've identified and corrected the cause of the hanging.  Using the example in the BCXHELP
was a bit confusing because there was no example output and the path specified in the
source code was ambiguous.  I got it all sorted out and would like to propose a slightly
improved example: 



$CPP
$CPPHDR

$HEADER
  #include <filesystem>
$HEADER
'------------------------------------------------------------------------------
FUNCTION MAIN()
    RAW AS std::filesystem::path p = "C:\temp"  ' Modify to suit your needs
    DIM S1$
    IF std::filesystem::exists(p) THEN
        IF std::filesystem::is_directory(p) THEN
            RBFOR(AUTO& e : std::filesystem::recursive_directory_iterator(p))
            S1$ = e.path().string().c_str()  ' Be careful not to accidentally change case
            IF (UCASE$(BCXSPLITPATH$(S1$, FEXT)) = ".EXE") OR _
                (UCASE$(BCXSPLITPATH$(S1$, FEXT)) = ".C")  OR _
                (UCASE$(BCXSPLITPATH$(S1$, FEXT)) = ".CPP") THEN
                PRINT S1$
            END IF
            RBNEXT
        ENDIF
    ELSE
        PRINT "Specified drive, path, and/or file extensions not found."
    END IF
    PRINT "ALL Done"
    PAUSE
END FUNCTION


Robert

Quote from: jcfuller on May 28, 2024, 03:58:26 PM
I did not remember RBFOR's addition to BCX but I did checked the help file anyway.
It's all Robert's fault! :) No reference in the help file index
With my failing memory I depend on you to keep me current.

James

Hi James:

It's good to hear from you.

BCX Help has been fixed and a new version uploaded.

Get it here

https://bcxbasiccoders.com/smf/index.php?topic=1063.msg5511#msg5511

I hope MrBCX can resolve your problem.

jcfuller

I did not remember RBFOR's addition to BCX but I did checked the help file anyway.
It's all Robert's fault! :) No reference in the help file index
With my failing memory I depend on you to keep me current.

James

MrBcx

James,

I'll have a look.

I confirmed the hanging using your example that can be found in BCXHELP:



$CPP
$CPPHDR

  $HEADER
  #include <filesystem>
  $HEADER
'------------------------------------------------------------------------------
FUNCTION main()
  RAW AS std::filesystem::path p = "D:/t"
  DIM S1$
  IF std::filesystem::exists(p) THEN
   IF std::filesystem::is_directory(p) THEN
    RBFOR(AUTO& e : std::filesystem::recursive_directory_iterator(p))
    S1$ = e.path().string().c_str()
    IF (UCASE$(BCXSPLITPATH$(S1$,FEXT)) = ".EXE") OR _
       (UCASE$(BCXSPLITPATH$(S1$,FEXT)) = ".C") OR _
       (UCASE$(BCXSPLITPATH$(S1$,FEXT)) = ".CPP") THEN
     ? S1$
    END IF
    RBNEXT
   ENDIF
  ELSE
   ? "CRAP"
  ENDIF
  ? "ALL Done"
  PAUSE
END FUNCTION



jcfuller

Kevin,
  I haven't coded in quite awhile, but of course now that I want to, I find an issue that started with 7.9.1.

I know we discussed c++ "Range Based For" Loops but I don't remember when or how it went..??

I use a BCXPP.DLL to do the translation.

The test bas source (VEC4C.bas) attached

'==============================================================================
RbFor ( auto itx : s)
If itx = B$ Then
cout << "B$ match" << endl
A$ = itx.c_str()
break
End If
cout << " " << itx << endl
RbNext

'------------------------------------------------------------------------------
Translated with 7.9.0
'------------------------------------------------------------------------------

    cout << "range-based for loop" << endl;
    for  (auto itx : s) {
        if(itx == B ) {
            cout << "B$ match" << endl;
            strcpy(A, itx.c_str());
            break;
        }
        cout << " " << itx << endl;
    };

'==============================================================================
The bas code in the BCXPP.DLL:
'==============================================================================

'c++11 range-based for loops
If LeftStr(Src$,"rbfor",1) Then
iReplace "rbfor" With "! for" In Src$
Src$ = Src$ & "{"
Function = 1
EndIf

If LeftStr(Src$,"rbnext",1) Then
Src$ = "}"
Function = 1
EndIf

'------------------------------------------------------------------------------
translated to:
    if(LeftStr(Src, "rbfor", 1)) {
        strcpy(Src, iReplace(Src, "rbfor", "! for"));
        strcat(Src, "{");
        return 1;
    }
    if(LeftStr(Src, "rbnext", 1)) {
        strcpy(Src, "}");
        return 1;
    }
'==============================================================================

Bcx Hangs on the
RbFor ( auto itx : s)
Line

James