if / else at compile time in C++?

C++17 if constexpr Oh yes, it has arrived: main.cpp #include <cassert> #include <type_traits> template<typename T> class MyClass { public: MyClass() : myVar{0} {} void modifyIfNotConst() { if constexpr(!isconst) { myVar = 1; } } T myVar; protected: static constexpr bool isconst = std::is_const<T>::value; }; int main() { MyClass<double> x; MyClass<const double> y; x.modifyIfNotConst(); y.modifyIfNotConst(); assert(x.myVar … Read more

How to parse html to React component?

You probably want to look deeper into dangerouslySetInnerHTML. Here is an example how to render HTML from a string in a React component: import React from ‘react’; import { render } from ‘react-dom’; const htmlString = ‘<h1>Hello World! 👋</h1>’; const App = () => ( <div dangerouslySetInnerHTML={{ __html: htmlString }} /> ); render(<App />, document.getElementById(‘root’)); … Read more

How do I define a compile-time *only* classpath in Gradle?

There has been a lot of discussion regarding this topic, mainly here, but not clear conclusion. You are on the right track: currently the best solution is to declare your own provided configuration, that will included compile-only dependencies and add to to your compile classpath: configurations{ provided } dependencies{ //Add libraries like lombok, findbugs etc … Read more

How to compile/install node.js(could not configure a cxx compiler!) (Ubuntu).

One-liner to install all needed dependencies(curl and git are not really needed, but are very useful and also needed if you install via nvm). sudo apt-get install build-essential libssl-dev curl git-core Last two dependencies are not always needed, but installing them is really usefull anyway and you probably need it later anyway. To only install … Read more

Can I use Qt without qmake or Qt Creator?

Sure you can. Although it is more convenient with qmake or CMake, you can do: CXXFLAGS += -Ipath_to_your_qt_includes LDFLAGS += -Lpath_to_your_qt_libs LDLIBS += -lqt-mt (for Qt3) or LDLIBS += -lQtCore -lQtGui (for Qt4, add what you need) my_prog: my_prog.cpp (in a makefile) Update – invoking moc: Quote from moc manpage: Here is a useful makefile … Read more

What are the advantages of just-in-time compilation versus ahead-of-time compilation?

Greater portability: The deliverable (byte-code) stays portable At the same time, more platform-specific: Because the JIT-compilation takes place on the same system that the code runs, it can be very, very fine-tuned for that particular system. If you do ahead-of-time compilation (and still want to ship the same package to everyone), you have to compromise. … Read more