Sorry for the delay in replying, I checked this problem twice more, a) on a VirutalBox where I installed Ubuntu from scratch and b) using the prebuilt docker container ubuntu:16.04.
ROOT version = 6.10.02 (latest production)
Compiled with cmake -Dcxx14=on -Dimt=on "../root-$ROOTVERSION"
root -b -q above-script.C
gives (you can also use above-script.C+):
root@c3cb0748db6e:/root-build# root -b -q /x/root-sort-function.C
------------------------------------------------------------
| Welcome to ROOT 6.10/02 http://root.cern.ch |
| (c) 1995-2017, The ROOT Team |
| Built for linuxx8664gcc |
| From tag v6-10-02, 6 July 2017 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------
Processing /x/root-sort-function.C...
In file included from input_line_2:2:
In file included from /usr/include/c++/5/string:40:
In file included from /usr/include/c++/5/bits/char_traits.h:39:
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:
/usr/include/c++/5/bits/predefined_ops.h:123:31: error: indirection requires pointer operand ('int' invalid)
{ return bool(_M_comp(*__it1, *__it2)); }
^~~~~~
/usr/include/c++/5/type_traits:2346:7: note: in instantiation of function template specialization '__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> >::operator()<int, int>' requested here
std::declval<_Fn>()(std::declval<_Args>()...)
^
/usr/include/c++/5/type_traits:2357:24: note: while substituting deduced template arguments into function template '_S_test' [with _Fn = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> >, _Args = (no value)]
typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
^
/usr/include/c++/5/type_traits:2362:14: note: in instantiation of template class 'std::__result_of_impl<false, false, __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> >, int, int>' requested here
: public __result_of_impl<
^
/usr/include/c++/5/functional:1981:35: note: in instantiation of template class 'std::result_of<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> > (int, int)>' requested here
typename _Res2 = typename result_of<_Func(_ArgTypes...)>::type>
^
/usr/include/c++/5/functional:2053:30: note: in instantiation of default argument for '_Callable<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> > >' required here
typename = _Requires<_Callable<_Functor>, void>>
^~~~~~~~~~~~~~~~~~~
/usr/include/c++/5/functional:2054:2: note: in instantiation of default argument for 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> >, void>' required here
function(_Functor);
^~~~~~~~
/usr/include/c++/5/bits/predefined_ops.h:130:14: note: while substituting deduced template arguments into function template 'function' [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int, int)> >, $1 = (no value), $2 = (no value)]
{ return _Iter_comp_iter<_Compare>(__comp); }
^
/usr/include/c++/5/bits/stl_algo.h:4729:54: note: in instantiation of function template specialization '__gnu_cxx::__ops::__iter_comp_iter<std::function<bool (int, int)> >' requested here
std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
^
/x/root-sort-function.C:9:5: note: in instantiation of function template specialization 'std::sort<__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> > >, std::function<bool (int, int)> >' requested here
sort(begin(order), end(order), compare);
To reproduce (I was too lazy to create a real dockerfile) run the following script in docker:
#!/bin/bash
# run from outside docker (from the directory containing this script):
# docker run -t -i -v "$(pwd):/x:ro" ubuntu:16.04 /bin/bash
# then execute /x/this-script.sh
set -ex
ROOTVERSION=6.10.02
download="https://root.cern.ch/download/root_v${ROOTVERSION}.source.tar.gz"
apt update
apt -y install wget perl python git dpkg-dev make g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev libpcre3-dev cmake
apt clean
wget -c "$download"
tar xzf "root_v${ROOTVERSION}.source.tar.gz"
# rm "root_v${ROOTVERSION}.source.tar.gz"
mkdir root-build
cd root-build
cmake -Dcxx14=on -Dimt=on "../root-$ROOTVERSION"
cmake --build . -- -j10
then source bin/thisroot.sh and run root -b -q /x/above-script.C