[ampl 24758] c++20

Hello everyone.

I am trying to run AMPL C++ API with C++20, but I am having some problems with this. Inside my AMPL folder /opt/ampl/amplapi/examples/cpp, I type:

g++ -std=c++11 -Wall -o firstexample firstexample.cc -I…/…/include -L…/…/lib -lampl

As suggested here https://groups.google.com/g/ampl/c/QAPhvArF7Bs/m/4NnDJs13BAAJ. Which works just fine, but if I try to do the same by using c++20

g++ -std=c++20 -Wall -o firstexample firstexample.cc -I…/…/include -L…/…/lib -lampl

I get the following messages:

In file included from …/…/include/ampl/amplexception.h:8,
from …/…/include/ampl/ep/errorinfo_ep.h:6,
from …/…/include/ampl/variant.h:7,
from …/…/include/ampl/ep/arg.h:4,
from …/…/include/ampl/dataframe.h:4,
from …/…/include/ampl/ampl.h:4,
from firstexample.cc:3:
…/…/include/ampl/format.h: In instantiation of ‘void fmt::internal::MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t) [with T = wchar_t; long unsigned int SIZE = 500; Allocator = std::allocator<wchar_t>; std::size_t = long unsigned int]’:
…/…/include/ampl/format.h:799:6: required from here
…/…/include/ampl/format.h:802:30: error: no matching function for call to ‘fmt::internal::MemoryBuffer<wchar_t, 500, std::allocator<wchar_t> >::allocate(std::size_t&, std::nullptr_t)’
802 | T new_ptr = this->allocate(new_capacity, FMT_NULL);
__
| ^~__
In file included from /usr/include/c++/11/string:41,
from /usr/include/c++/11/bits/locale_classes.h:40,
from /usr/include/c++/11/bits/ios_base.h:41,
from /usr/include/c++/11/ios:42,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from firstexample.cc:1:
/usr/include/c++/11/bits/allocator.h:179:7: note: candidate: ‘constexpr _Tp
std::allocator< >::allocate(std::size_t) [with _Tp = wchar_t; std::size_t = long unsigned int]’
179 | allocate(size_t __n)
__*| ^
~__
__
/usr/include/c++/11/bits/allocator.h:179:7: note: candidate expects 1 argument, 2 provided*__
In file included from …/…/include/ampl/amplexception.h:8,
from …/…/include/ampl/ep/errorinfo_ep.h:6,
from …/…/include/ampl/variant.h:7,
from …/…/include/ampl/ep/arg.h:4,
from …/…/include/ampl/dataframe.h:4,
from …/…/include/ampl/ampl.h:4,
from firstexample.cc:3:
…/…/include/ampl/format.h: In instantiation of ‘void fmt::internal::MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t) [with T = char; long unsigned int SIZE = 500; Allocator = std::allocator; std::size_t = long unsigned int]’:
…/…/include/ampl/format.h:799:6: required from here
…/…/include/ampl/format.h:802:30: error: no matching function for call to ‘fmt::internal::MemoryBuffer<char, 500, std::allocator >::allocate(std::size_t&, std::nullptr_t)’
802 | T new_ptr = this->allocate(new_capacity, FMT_NULL);
__
| ^
~__
In file included from /usr/include/c++/11/string:41,
from /usr/include/c++/11/bits/locale_classes.h:40,
from /usr/include/c++/11/bits/ios_base.h:41,
from /usr/include/c++/11/ios:42,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from firstexample.cc:1:
/usr/include/c++/11/bits/allocator.h:179:7: note: candidate: ‘constexpr _Tp
std::allocator< >::allocate(std::size_t) [with _Tp = char; std::size_t = long unsigned int]’
179 | allocate(size_t __n)
__*| ^
~__
__
/usr/include/c++/11/bits/allocator.h:179:7: note: candidate expects 1 argument, 2 provided*__

I would like to know if someone ever tried using the AMPL C++ API with C++20.

Thanks and best regards.

The version of the API currently being distributed has a different format.h file which was adjusted to allow compiling with C++20 some time ago. Could you please upgrade to the latest version and try again?

I did a small test, I changed the line 802 of file /opt/ampl/amplapi/include/ampl/format.h from

T *new_ptr = this->allocate(new_capacity, FMT_NULL);

to

T *new_ptr = this->allocate(new_capacity);

And now it works fine. Is it some setting from my side or a lack in AMPL?

Thanks and BR.

Sorry, just saw the other comment. Problem solved, just had to update to the most recent version.

Thank you very much.

The issue is that the version of the API you are using was exposing an old version for fmtlib. Even though that fix got it to compile, it is possible that you may face some other issues. The current version of the API does not depend on it anymore.