Compilation issue with custom state type with clang only
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the linked Godbolt reproducer and compare clang++ with the compilers that accept it. Inspect the boost/numeric/odeint.hpp inclusion path and the vector_space_algebra use with std::pair; done means the shown program compiles with clang++ without moving the operator definitions before the odeint include.
Written by the indexing model from the issue text.
Description
In the code below, I am working with a custom state-type (a std::pair in this case). The code compiles with g++, icc, msvc. With clang however, compilation fails. In order to get it to build successfully, I apparently need to define operator+() and operator*() for the state type before including the odeint header. Link to godbolt: https://godbolt.org/z/6eavzdxbf
#include <cstdlib>
#include <utility>
#include <boost/numeric/odeint.hpp> // if included here, compilations fails with clang++
using state_type = std::pair<double, double>;
using deriv_type = state_type;
using time_type = double;
state_type operator+(state_type a, state_type const& b);
state_type operator*(state_type a, time_type b);
state_type operator*(time_type b, state_type a);
//~ #include <boost/numeric/odeint.hpp> // if included here, no error!
state_type operator+(state_type a, state_type const& b) {
a.first += b.first;
a.second += b.second;
return a;
}
state_type operator*(state_type a, time_type b) {
a.first *= b;
a.second *= b;
return a;
}
state_type operator*(time_type b, state_type a) {
return a * b;
}
void harmonic_oscillator(const state_type& x, deriv_type& dxdt, time_type) {
static auto constexpr gam = 0.1;
dxdt.first = x.second;
dxdt.second = -x.first - gam*x.second;
}
namespace bno = boost::numeric::odeint;
using stepper_type = bno::runge_kutta_dopri5<state_type, double, deriv_type, time_type, bno::vector_space_algebra>;
int main() {
state_type x0{1.0, 0.0};
// just to see if the operators work...
x0 * 1.;
2. * x0;
x0 + x0;
stepper_type stepper;
time_type const dt = 0.005;
for (time_type t = 0; t < 10; t += dt) {
stepper.do_step(harmonic_oscillator, x0, t, dt);
std::cout << t << '\t' << x0.first << '\t' << x0.second << '\n';
}
return EXIT_SUCCESS;
}
- Dominant language
- C++
- Stars
- 55
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/odeint
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 43/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
code-quality libc++
Difficulty 1/5 Under an hour Newbie friendliness 82/100
llvm/llvm-project#229284 ·
Maintainers usually reply within 1 day
-
test-issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
llvm/offload-test-suite#1557 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
iOS: hidden scale bar invalidates its intrinsic content size on every layout pass of MLNMapViewOpen
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
maplibre/maplibre-native#4723 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
HarbourMasters/Shipwright#7320 ·
Maintainers usually reply within 1 day