- What is wrong with my template gJoin() function? - 2 Updates
- Synchronizing openFrameworks threads - 2 Updates
- #define - 4 Updates
- Undefined Behaviour - 1 Update
- What is wrong with my template gJoin() function? - 4 Updates
- casting that's a lot of extra typing :-) - 2 Updates
- is there a C++ version of the strtok() function? - 1 Update
Szyk Cech <szykcech@spoko.pl>: Jul 06 05:54PM +0200 Hi I want to write nice join template function. In order to work with different containers and with wide and narrow strings it must be template. Now I have some thing like this: /** * @brief Joins strings in container. * @param aStringList an container wiht strings. * @param aDelimiter string witch joins strings in container. * @result String joined with delimiter. */ template<template<typename> typename tContainer, typename tString> tString gJoin(const tContainer<tString>& aStringList, const tString& aDelimiter) { tString lResult; for(tString lPart : aStringList) { if(lResult.size() > 0) lResult += aDelimiter; lResult += lPart; } return lResult; } But it not works. My g++ is: gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1) I learn that it should work from: https://en.cppreference.com/w/cpp/language/template_parameters Error is like this: /home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp: In member function 'void StringTest::test7()': /home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp:126:76: error: no matching function for call to 'gJoin<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::__cxx11::string>(std::vector<std::__cxx11::basic_string<char> >&, std::__cxx11::basic_string<char>)' std::string lTest1A(gJoin<vector<string>, string>(lVector1, string(" "))); ^ In file included from /home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp:4:0: /home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Include/EnergoKodTools2/Strings.h:148:9: note: candidate: template<template<class> class tContainer, class tString> tString ekt2::gJoin(const tContainer<tString>&, const tString&) tString gJoin(const tContainer<tString>& aStringList, const tString& aDelimiter) ^~~~~ /home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Include/EnergoKodTools2/Strings.h:148:9: note: template argument deduction/substitution failed: Tests/CMakeFiles/EnergoKodTools2Test.dir/build.make:158: recipe for target 'Tests/CMakeFiles/EnergoKodTools2Test.dir/Src/StringTest.cpp.o' failed make[2]: *** [Tests/CMakeFiles/EnergoKodTools2Test.dir/Src/StringTest.cpp.o] Error 1 make[1]: *** [Tests/CMakeFiles/EnergoKodTools2Test.dir/all] Error 2 make: *** [all] Error 2 CMakeFiles/Makefile2:122: recipe for target 'Tests/CMakeFiles/EnergoKodTools2Test.dir/all' failed Makefile:129: recipe for target 'all' failed 17:45:51: Proces "/usr/bin/cmake" zakończył się kodem wyjściowym 2. Błąd budowania / instalowania projektu EnergoKodTools2 (zestaw narzędzi: Desktop Qt 5.12.3 GCC 64bit2) Podczas wykonywania kroku "Wersja CMake" please help me, best regards, and thanks in advance Szyk Cech |
Szyk Cech <szykcech@spoko.pl>: Jul 06 07:59PM +0200 Thanks a lot!!! I improve my code with your help! And it pass all my tests now. Problem was that I rely on Qt Creator buildin C++ parser (based on CLang compiler libraries). And how ever I have compile able and valid template function code, I try crazy calls of this function, because I believe in parser. Apparently it does not recognize C++17 fully. Not sure, but maybe it is not upgraded to newest version (but I have newest Qt Creator). Final version of my gJoin() template function looks like: /** * @brief Joins wide and narrow strings in any container. * @param aStringList an container with strings. * @param aDelimiter string witch joins strings in container. * @result String joined with delimiter. * @warning Don't call this function with different string types * as containter template parameter and as delimiter - if you do this you will * get compile error. */ template<template<typename> typename tContainer, typename tString> tString gJoin(const tContainer<tString>& aStringList, const tString& aDelimiter) { tString lResult; for(tString lPart : aStringList) { if(not lResult.empty()) lResult += aDelimiter; lResult += lPart; } return lResult; } |
bitrex <user@example.net>: Jul 06 01:39PM -0400 I have two Thread subclasses in the openFrameworks API that receive data from a third thread via a lock-free FIFO, e.g: <https://openframeworks.cc/documentation/utils/ofThreadChannel/> process it a bit and then transmit it out to their own independent hardware serial ports. I am looking for a suggestion on what C++1x technique or library I could use to allow synchronizing the output data transmission routine timing to a thread-safe master reference clock, but allow the data input to the threads to remain asynchronous. |
bitrex <user@example.net>: Jul 06 01:43PM -0400 On 7/6/19 1:39 PM, bitrex wrote: > use to allow synchronizing the output data transmission routine timing > to a thread-safe master reference clock, but allow the data input to the > threads to remain asynchronous. I guess since the threads are already getting their xmit data via a FIFO of that type they could also receive timing clock data the same way... |
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 06 06:59AM -0700 On Friday, July 5, 2019 at 7:23:03 PM UTC-4, G G wrote: > On Friday, July 5, 2019 at 7:20:02 PM UTC-4, G G wrote: > > On Friday, July 5, 2019 at 7:10:24 PM UTC-4, Öö Tiib wrote: ... > > yes > i stop at line 34. preprocessor macros > are you say those preprocessor statement would not work in C++? The #define itself works the same way in both languages. However, which definition is given to that macro depends upon whether __STDC__ is #defined, and also upon how it is defined. The double underscores at the beginning mean that__STDC__ is a reserved identifier for C++, but the C++ standard specifies nothing about what value it has. So yes, the wrong definition for that prototype might be chosen. More directly to the point, those preprocessor directives (the two #defines for PROTOTYPE, as well at the #if, #else, and
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment