Simple complex calculation failed

1/ I have installed
on my xubuntu 20.04
(installed the root directories on my share directory)

2/ root run very well on my old program

3/ I tried to run the following program:
void testComplex(){
using namespace std::complex_literals;
std::complex z1 = 1i * 1i;
std::cout << "i * i = " << z1 << ‘\n’;}

$root -l
root [0]
In file included from input_line_8:1: error: expected namespace name
using namespace std::complex_literals;
root [1]

4/ any idea on what’s wrong ?

Thanks in advance for help
Information about my system at the end

_ROOT Version:
ROOT 6.24/00

Linux 5.4.0-74-generic #83-Ubuntu
|LSB Version:|core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch|
|Distributor ID:|Ubuntu|
|Description:|Ubuntu 20.04.2 LTS|

_Compiler:$ dpkg --list | grep compiler
antlr 2.7.7+dfsg-10build1 all language tool for constructing recognizers, compilers etc
g++ 4:9.3.0-1ubuntu2 amd64 GNU C++ compiler
g+±7 7.5.0-6ubuntu2 amd64 GNU C++ compiler
g+±9 9.3.0-17ubuntu1~20.04 amd64 GNU C++ compiler
gcc 4:9.3.0-1ubuntu2 amd64 GNU C compiler
gcc-7 7.5.0-6ubuntu2 amd64 GNU C compiler
gcc-9 9.3.0-17ubuntu1~20.04 amd64 GNU C compiler
gfortran 4:9.3.0-1ubuntu2 amd64 GNU Fortran 95 compiler
gfortran-9 9.3.0-17ubuntu1~20.04 amd64 GNU Fortran compiler
kuipc 20061220+dfsg3-4.4build1 amd64 CERNLIB data analysis suite - KUIP compiler
libantlr-java 2.7.7+dfsg-10build1 all language tool for constructing recognizers, compilers etc (java library)
libecj-java 3.16.0-1 all Eclipse Java compiler (library)
libllvm11:amd64 1:11.0.0-2~ubuntu20.04.1 amd64 Modular compiler and toolchain technologies, runtime library
libluajit-5.1-2:amd64 2.1.0~beta3+dfsg-5.1build1 amd64 Just in time compiler for Lua - library version
libluajit-5.1-common 2.1.0~beta3+dfsg-5.1build1 all Just in time compiler for Lua - common files
libparams-validationcompiler-perl 0.30-1 all module to build an optimized subroutine parameter validator
libplexus-archiver-java 3.6.0-2 all Archiver plugin for the Plexus compiler system
libxkbcommon0:amd64 0.10.0-1 amd64 library interface to the XKB compiler - shared library
uil 2.3.8-2build1 amd64 Motif - UIL (User Interface Language) compiler


This text will be hidden

std::complex_literals is a C++14 feature. Probably your ROOT is built for C++11 and therefore the interpreter does not know about that namespace (hence the errror). You can check what C++ standard ROOT was built for by running root-config --cflags at the terminal and check the -std=c++?? flag.


1/ 1000 thanks for your help:

2/ test
$ root-config --cflags
-pthread -std=c++11 -m64 -I/local/home/laurent/share/root/include

c++11 !!!

any ideas to use complex with my version of root?

You can use std::complex, just not std::complex_literals, i.e. the 1i notation.

Or you can install ROOT e.g. via conda, which gives you a ROOT with C++17 support (see Installing ROOT - ROOT ).


Perfect and thanks again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.