This is a very terse list of steps to be done to be able to start testing concepts with G++.
While this article is still relevant, there is lots of more relevant information about Concepts Lite in the articles section. It has many articles not just on how to build GCC, but also how to use Concepts Lite and what types of concepts there are.
useradd -m betagcc
su - betagcc
git clone https://github.com/gcc-mirror/gcc.git
cd gcc
${HOME}
. The prefix doesn’t expand the bash tilde ~
, a full path must be used.:./configure --disable-bootstrap --enable-languages=c,c++ --prefix=${HOME}/gccbin
-j
parameter with number of cores in your system.make -j3
make install
mkdir -p ~/bin
/home/betagcc/bin/g++
to /home/betagcc/gccbin/bin/g++
.ln -sf ${HOME}/gccbin/bin/g++ ~/bin/g++
~/bin
to PATH
. Add it to the beginning because you’re overriding g++ from the system. Add this line to .bashrc
:PATH=~/bin:$PATH
.bashrc
to add ~/bin
to your path.source .bashrc
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/betagcc/gccbin/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --disable-bootstrap --enable-languages=c,c++
Thread model: posix
gcc version 6.0.0 20150807 (experimental) (GCC)
Makefile below.
// concepts.cpp #include <type_traits> /* concept Stack<typename X> { typename value_type; void push(X&, const value_type&); void pop(X&); value_type top(const X&); bool empty(const X&); }; */ /* concept_map InputIterator<char*> { typedef char value_type; typedef char& reference; typedef char* pointer; typedef std::ptrdiff_t difference_type; }; */ template<typename T> //requires std::is_arithmetic<T>::value requires false class Foo { }; struct B {}; int main() { Foo<int> a; return 0; }
Makefile: Remember to use the --std=c++1z
switch. Without it, concepts will not be available.
all: g++ --std=c++1z concepts.cpp -o concepts
This will print an error similar to:
g++ --std=c++1z concepts.cpp -o concepts concepts.cpp: In function ‘int main()’: concepts.cpp:34:9: error: template constraint failure Foo<int> a; ^ concepts.cpp:34:9: note: constraints not satisfied concepts.cpp:34:9: note: ‘false’ evaluated to false Makefile:2: recipe for target 'all' failed make: *** [all] Error 1
This is a very brief introduction to concepts and how to build G++ with concepts enabled.