Skip to content

Maybe it'll be better to import std in the modules #1

Closed
@ChuanqiXu9

Description

@ChuanqiXu9

Hi, excited to see the experiments in https://anarthal.github.io/cppblog/modules2

I just want to note that it may better to improve the experiments by importing std module in the library itself.

For example, for https://github.com/cppalliance/boost2/blob/master/libs/math/module/core.cxx we can rewrite it as:

module;

#define BOOST_MATH_POLICIES_AS_MODULE
#define BOOST_MATH_AS_MODULE
#define BOOST_MATH_STANDALONE


#if STD_MODULE_AVAILABLE
import std.compat;
#else
// For config:
#include <algorithm>  // for min and max
#include <limits>
#include <cmath>
#include <climits>
#include <cfloat>
#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
#  include <math.h>
#endif
#include <type_traits>
#include <cfenv>

// For error_handling.hpp and policies.hpp:
#include <iomanip>
#include <string>
#include <cstring>
#include <typeinfo>
#include <cerrno>
#include <complex>
#include <cmath>
#include <cstdint>
#include <stdexcept>
#include <boost/math/tools/mp.hpp>
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/throw_exception.hpp>
#include <sstream>
#include <limits>
#include <cstdint>
#include <cstddef>
#include <boost/math/tools/assert.hpp>
#include <limits>
#include <climits>
#include <cstdint>
#include <cfloat> // LDBL_MANT_DIG

...
#end STD_MODULE_AVAILABLE

Also in https://github.com/cppalliance/boost2/blob/master/libs/math/module/sf.cxx, I see you tried to import std, but at least that won't work for libc++

module;

#define BOOST_MATH_SF_AS_MODULE
#define BOOST_MATH_AS_MODULE
#define BOOST_MATH_STANDALONE

#if defined(__cpp_lib_modules) && __cpp_lib_modules >= 202207L

import std;
import std.compat;

#else

#include <cmath>
#include <climits>
#include <algorithm>
#include <type_traits>
#include <cstdint>
#include <limits>
#include <mutex>
#include <vector>
#include <string>

#endif

#include <boost/math/tools/promotion.hpp>

export module boost.math.special_functions;

Since __cpp_lib_modules is defined by the library, but we didn't include any library here. Also __cpp_lib_modules is not defined by libc++. So we probably have to do something manually here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions