GithubHelp home page GithubHelp logo

Exposing map of all units about units HOT 3 CLOSED

llnl avatar llnl commented on August 28, 2024
Exposing map of all units

from units.

Comments (3)

phlptp avatar phlptp commented on August 28, 2024

I had thought about this before. In general I didn't want to include the <unordered_map> header in units.hpp and having that symbol be exposed would lead to some complications in other libraries I use units in that generate shared libraries.

What I had thought about was adding a little wrapper in the detail::testing namespace defined at the bottom of the units.hpp file that just returned a const reference to some of the main maps, but only if the ENABLE_UNIT_TESTING or some other compile time define was enabled. I will probably need this at some point for additional testing.

from units.

Hunter522 avatar Hunter522 commented on August 28, 2024

Yeah that was one drawback I noticed with including <unordered_map>, unnecessarily bloating your include file. Though I just now noticed that std::unordered_map is already made available from this include tree:

  • "units.hpp"
    • "units_definitions.hpp"
      • "units_decl.hpp"
        • <functional>
          • <unordered_map> tho only if __cplusplus > 201402L...or C++14 which I am using C++17

So <unordered_map> in units.hpp is actually not necessary for compilers >= C++14. Though if you're trying to target >=C++11 then I'm guessing you'd have to include it. I see no way to forward declare std::unordered_map [1]

As for the symbol conflict, I like your idea of having a separate const reference. I tried that and seemed to work fine:

units.hpp:

namespace units {
...
using smap = std::unordered_map<std::string, precise_unit>;
extern const smap& base_unit_vals_ref;

units.cpp:

static const smap base_unit_vals{
...
}

const smap& base_unit_vals_ref = base_unit_vals;

[1] https://blog.magnum.graphics/backstage/forward-declaring-stl-container-types/

from units.

phlptp avatar phlptp commented on August 28, 2024

I am going to close this at the next release as I think this functionality is now in place

from units.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.