We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Other Concepts
- C++ Class Templates
- Discussions
C++ Class Templates
C++ Class Templates
Sort by
recency
|
240 Discussions
|
Please Login in order to post a comment
As many have noticed, some test cases fail due to timeout when submitting under C++ 14 or C++ 20 but not when submitting for C++ 11.
It has also been pointed out that disabling ios_base::sync_with_stdio at the top of main() resolves the issue. Disabling this syncronization "... the C++ standard streams are allowed to buffer their I/O independently, which may be considerably faster in some cases." - https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio.html
I was curious why C++ 11 would be faster or not suffer from this issue, so I went poking around Compiler Explorer (https://godbolt.org/). I was not able to find any difference in various GCC versions and only minor differences with Clang when compiling with -std=c++11 vs -std=c++14 so long as the same compiler flags were used with each case. This leads me to wonder if different compiler flags are used when selecting C++ 11. Perhaps a different optimization levels? Another possibility is that the difference could be in more at a system level. If your compilation / execution task is offloaded to a different set of resources depending on the selected C++ version, then either system load or hardware performance could be to blame.
Had execution time problems with c++ v14 so I used v11 which worked fine. (using v14 random tests where passing on each submission)
Well said! Class templates are incredibly powerful in C++, especially for creating reusable and type-safe components. Gurubhai247 com Login
Here is C++ class templates solution - https://programmingoneonone.com/hackerrank-cpp-class-templates-problem-solution.html