Lynn McGuire <lynnmcguire5@gmail.com>: Jan 06 11:00PM -0600 So what is the best way to convert a Fortran implied do loop to C++ ? WRITE (2,2) (N (I), I = 1, 80) 2 FORMAT(' ',80A1) Thanks, Lynn |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jan 07 12:55PM > So what is the best way to convert a Fortran implied do loop to C++ ? > WRITE (2,2) (N (I), I = 1, 80) > 2 FORMAT(' ',80A1) Presumably the bounds are not always literals, and you probably also want to general solution the works for multiple implied loops, some of which might be nested? So not much! My first question would be how you translate WRITE/FORMAT combinations with no loops as that's going to form the basis of a solution. (I presume you know Fortran well enough to know that this is not the same as putting a loop round the write.) -- Ben. |
Richard Damon <Richard@Damon-Family.org>: Jan 07 11:07AM -0500 On 1/7/23 7:55 AM, Ben Bacarisse wrote: > with no loops as that's going to form the basis of a solution. > (I presume you know Fortran well enough to know that this is not the > same as putting a loop round the write.) Althogh in C++ you COULD put the loop around the write equivalent since C++ doesn't automatically take the first character as carriage control and add the new line to the end (if you use the right functions). |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jan 07 09:48PM > since C++ doesn't automatically take the first character as carriage > control and add the new line to the end (if you use the right > functions). I would expect that with a clean translation the carriage control handling (if wanted) would just come out in the wash. Even in modern Fortran (where the "carriage control" malarkey is obsolete) you can't just turn an implied loop into an explicit one. Presumably the translating software already has some mechanism to iterate through the format and that's what has to be driven by the implied loop. If, as I suppose is possible, the first character is still to be treated specially, that should just work out correctly as the code iterates through the format. -- Ben. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jan 07 10:41PM > If, as I suppose is possible, the first character is still to be treated > specially, that should just work out correctly as the code iterates > through the format. To add a bit more detail, I image that formats will be turned into run-time objects containing a 'compiled' version of the format mini-language. A statement like WRITE(*, 2) A, X 2 FORMAT(I2, F5.2) would turn into format_2.start(); format_2.write(UNIT_STAR, A); format_2.write(UNIT_STAR, X); format_2.end(); where the write method is a templated method that advances an internal pointer in the format "list" (it may, in fact, be a cyclic graph). And WRITE(*,2) (N(I), X(I), I = 1, 6) would turn into format_2.start(); for (int i = 1; i <= 6; i++) { format_2.write(STAR, N[i]); format_2.write(STAR, X[i]); } format_2.end(); The member function 'end' should be idempotent, because the write function will also call it when the last format specification is used. I'm sure this is turn out to be way more complicated that it looks to me right now, but this feel like the gist of what's needed. -- Ben. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jan 07 10:46PM > mini-language. A statement like > WRITE(*, 2) A, X > 2 FORMAT(I2, F5.2) It might have made more sense to use a format that could be used by an external loop like DO 10 I = 1, 6 WRITE(*, 2) A(I), X(I) 10 END DO but which while still being sensible would give a different result. For example, I might have used 2 FORMAT(3(I2, F5.2)) The rest remains the same. -- Ben. |
Aaron Gray <aaronngray@gmail.com>: Jan 06 04:14PM -0800 Hi, I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 0...7 - unsigned char 8..15 - unsigned short 16...31 - unsigned int 32...63 - unsigned long 64...127 - unsigned long long 128... - unsigned long long [] - array ``` #include <cstddef> template <size_t BITS> class bitset { public: .... WORDTYPE data; .... }; ``` I am looking for solutions both with and without concepts for comparison, if its possible without and its simpler I will use that solution unless there is some real advantages to using concepts. Many thanks in advance, Aaron |
Aaron Gray <aaronngray@gmail.com>: Jan 06 05:48PM -0800 On Saturday, 7 January 2023 at 00:14:35 UTC, Aaron Gray wrote: > .... > }; > ``` ChatGTP has given me the following :- ``` #include <type_traits> template <size_t BITS> class bitset { public: static_assert(BITS > 0, "Number of bits must be positive"); using WORDTYPE = typename std::conditional<BITS <= 8, unsigned char, typename std::conditional<BITS <= 15, unsigned short, typename std::conditional<BITS <= 31, unsigned int, typename std::conditional<BITS <= 63, unsigned long, typename std::conditional<BITS <= 127, unsigned long long, unsigned long long[]>::type>::type>::type>::type; WORDTYPE data; // ... }; ``` A good start, but withh two bugs, a missing extra '>::type' and the array really wants to be a whole new template specialization with WORDTYPE :- unsigned long long[(BITS+127)/128] > I am looking for solutions both with and without concepts for comparison, if its possible without and its simpler I will use that solution unless there is some real advantages to using concepts. I am thinking concepts may be necessary ? If you would like to help on the journey it would be well appreciated :) Aaron |
Muttley@dastardlyhq.com: Jan 07 11:19AM On Fri, 6 Jan 2023 16:14:26 -0800 (PST) >its possible without and its simpler I will use that solution unless there is >some real advantages to using concepts. >Many thanks in advance, Do you own coursework. |
"Öö Tiib" <ootiib@hot.ee>: Jan 07 08:49AM -0800 > Hi, > I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. But it is trivial with std::conditional in <type_traits>. Also the example in <https://en.cppreference.com/w/cpp/types/conditional> is almost what you asked for. So what is the problem? Otherwise you can freely get innumerable implementations of bitset. The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular. So you should be swimming over your head lake of code ... not be asking for more of it. |
Aaron Gray <aaronngray@gmail.com>: Jan 07 09:30AM -0800 On Saturday, 7 January 2023 at 16:49:46 UTC, Öö Tiib wrote: > The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular. > So you should be swimming over your head lake of code ... not be asking for more > of it. I am trying to put together a very efficient implementation to deal with fixed number of bits for dealing with lookahead sets for closure FIRST set guards for recursive decent parsers and a recursive descent parser generator. So want to use my own specific implmentation. Aaron |
Aaron Gray <aaronngray@gmail.com>: Jan 07 09:32AM -0800 On Saturday, 7 January 2023 at 11:19:27 UTC, Mut... wrote: > >some real advantages to using concepts. > >Many thanks in advance, > Do you own coursework. No I am an open source software engineer. Aaron |
"Öö Tiib" <ootiib@hot.ee>: Jan 07 10:09AM -0800 > > So you should be swimming over your head lake of code ... not be asking for more > > of it. > I am trying to put together a very efficient implementation to deal with fixed number of bits for dealing with lookahead sets for closure FIRST set guards for recursive decent parsers and a recursive descent parser generator. So want to use my own specific implmentation. The std::conditional runs compile time so you can not get more efficient than that. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 07 12:45PM -0800 On 1/6/2023 5:48 PM, Aaron Gray wrote: >> }; >> ``` > ChatGTP has given me the following :- [...] Ouch. ChatGTP seems to train itself when somebody has to correct its generated code that it likely lifted from somebody else. Also, is the correction correct itself? |
Lynn McGuire <lynnmcguire5@gmail.com>: Jan 06 07:04PM -0600 "TIOBE Index for January 2023″ https://www.tiobe.com/tiobe-index/ "C++ is TIOBE's programming language of the year 2022. It has won this title because C++ gained most popularity (+4.62%) in 2022. Runners up are C (+3.82%) and Python (+2.78%). Interestingly, C++ surpassed Java to become the number 3 of the TIOBE index in November 2022. The reason for C++'s popularity is its excellent performance while being a high level object-oriented language. Because of this, it is possible to develop fast and vast software systems (over millions of lines of code) in C++ without necessarily ending up in a maintenance nightmare." Lynn |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment