Why am I unable to declare a string type variable in GCC 13.x version with #pragma GCC target(…)

Advertisements I just updated my GCC compiler version to 13.1 from 11.4. And I found the following code which used to work on my old GCC 11.4 no longer works on GCC 13.1. #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") #include <iostream> int main() { string s = "Hello World!"; cout << s << endl; }… Read More Why am I unable to declare a string type variable in GCC 13.x version with #pragma GCC target(…)

error while compiling simple c++ file with libavformat library

Advertisements i create simple c++ file called test.cpp #include <iostream> #include <libavformat\avformat.h> using namespace std; int main() { cout << "Hello, World!"; return 0; } and using g++ in terminal to compile test.cpp file with the command : g++ test.cpp -o test i get this error => test.cpp:2:10: fatal error: libavformat\avformat.h: No such file or… Read More error while compiling simple c++ file with libavformat library

How can I define a static templated variable without knowing the template data type?

Advertisements Let’s say I have the following struct to store a reference to a class member variable: template <typename R> struct Foo { R ref; int info; }; class Bar { void* run(); } I want to create a const variable of type foo that immediately sets the ref param as follows: const Foo theVar… Read More How can I define a static templated variable without knowing the template data type?

I have installed gcc-12 and g++-12 on my Ubuntu 22.04 system. How do I make them the default versions used when I call gcc/g++ in terminal?

Advertisements I have installed gcc-12 and g++-12 on my Ubuntu 22.04 system. How do I make them the default versions used when I call gcc/g++ in terminal? >Solution : First you need to remove the current gcc and g++ symbolic links: sudo rm /usr/bin/gcc sudo rm /usr/bin/g++ Then, create a new symbolic link for gcc… Read More I have installed gcc-12 and g++-12 on my Ubuntu 22.04 system. How do I make them the default versions used when I call gcc/g++ in terminal?

Why is_same compilation failed when use enable_if, but is_same_v pass

Advertisements environment x86-64 gcc 12.2, where you can try at https://godbolt.org/z/eTvTf7n3n and https://godbolt.org/z/4W7hM3Pzs code #include <type_traits> // pass template<std::enable_if_t<!std::is_same_v<int, int>, bool> = 0> void f1(){ } // Compilation failed template<std::enable_if_t<!std::is_same<int, int>::value, bool> = 0> void f2(){ } int main() { } question Why function f1 and f2 behaves differently? is_same_v is just a constant time… Read More Why is_same compilation failed when use enable_if, but is_same_v pass

C++ higher order functions: different results when declaring multiple functions

Advertisements I was plying with higher order functions, and I started getting different results when I created two instances and assigning them to variables. I reduced the issue to the following example: #include <iostream> using ColorGetter = int(*)(void); auto paint(const ColorGetter &f) { return [&]() { return f(); }; } int colorA() { return 10;… Read More C++ higher order functions: different results when declaring multiple functions