Using Approx with the single-include catch2/catch.hpp

359 views
Skip to first unread message

Ben FrantzDale

unread,
May 16, 2019, 12:40:19 PM5/16/19
to CATCH
We use the old catch and are trying to upgrade to Catch2. I have a file that includes catch just to use its Approx class. However, when using the massive single-include catch.hpp, I see that the definitions of things like Approx::Approx(double) are buried behind #ifdefs. If I #define CATCH_IMPL, then it sees those functions, but then is missing things IReporterFactoryPtr, which is defined above, but hidden by CATCH_CONFIG_EXTERNAL_INTERFACES. If I additionally #define CATCH_CONFIG_EXTERNAL_INTERFACES. Then I need ratio_string, so I #define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER... then I have a giant pile of multiple-definitions errors.

Is there a way to use Approx in a header-only way?

Martin Hořeňovský

unread,
May 17, 2019, 3:18:22 PM5/17/19
to Ben FrantzDale, CATCH
If you include the header, you can just use Approx without any extra defines. You will however, need one TU somewhere with CATCH_CONFIG_IMPL for linking to work properly.

xarn@DESKTOP-B2A3CNC:/mnt/c/ubuntu/temp :) head catch.hpp
/*
 *  Catch v2.7.2
 *  Generated: 2019-04-22 23:13:14.687465
 *  ----------------------------------------------------------
 *  This file has been merged from multiple headers. Please don't edit it directly
 *  Copyright (c) 2019 Two Blue Cubes Ltd. All rights reserved.
 *
 *  Distributed under the Boost Software License, Version 1.0. (See accompanying
 *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 */
xarn@DESKTOP-B2A3CNC:/mnt/c/ubuntu/temp :) cat approx.cpp
#include "catch.hpp"

TEST_CASE("Approx") {
    REQUIRE(Approx(1) == 1);
}

xarn@DESKTOP-B2A3CNC:/mnt/c/ubuntu/temp :) clang++ -c approx.cpp -std=c++11
xarn@DESKTOP-B2A3CNC:/mnt/c/ubuntu/temp :)

On Thu, 16 May 2019 at 18:40, Ben FrantzDale <b...@formlabs.com> wrote:
We use the old catch and are trying to upgrade to Catch2. I have a file that includes catch just to use its Approx class. However, when using the massive single-include catch.hpp, I see that the definitions of things like Approx::Approx(double) are buried behind #ifdefs. If I #define CATCH_IMPL, then it sees those functions, but then is missing things IReporterFactoryPtr, which is defined above, but hidden by CATCH_CONFIG_EXTERNAL_INTERFACES. If I additionally #define CATCH_CONFIG_EXTERNAL_INTERFACES. Then I need ratio_string, so I #define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER... then I have a giant pile of multiple-definitions errors.

Is there a way to use Approx in a header-only way?

--
You received this message because you are subscribed to the Google Groups "CATCH" group.
To unsubscribe from this group and stop receiving emails from it, send an email to catch-forum...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/catch-forum/75a1e653-2cb7-4bf1-ad9b-89a3afcb3add%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages