GithubHelp home page GithubHelp logo

thelink2012 / any Goto Github PK

View Code? Open in Web Editor NEW
141.0 141.0 37.0 49 KB

Implementation of std::experimental::any, including small object optimization, for C++11 compilers

License: Boost Software License 1.0

C++ 98.51% CMake 1.49%

any's People

Contributors

barracuda156 avatar duskmushroom avatar johanmabille avatar nitro44x avatar rockinroel avatar t1h0n avatar thelink2012 avatar trueqbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

any's Issues

Segmentation fault when sizeof(std::string) <= 2 * sizeof(void*)

When using a recent g++ and libstdc++ with -D_GLIBCXX_USE_CXX11_ABI=0, or an older version of g++, sizeof(std::string) is one word. In that case the std::string is placed in stack storage. However, this causes a segmentation fault in some cases.

You can also reproduce this issue with the new ABI and libc++ by increasing the size of stack_storage_t to 4 * sizeof(void*).

Here's a code sample that reproduces the issue:

#include "any.hpp"

#include <iostream>

std::string asString(const linb::any &v)
{
  if (v.type() == typeid(std::string))
    return linb::any_cast<std::string>(v);
  else
    return "";
}

int main()
{
  linb::any a;
  {
    a = std::string("test");
  }
  std::cout << "a: " << asString(a) << std::endl;
}

Move from rvalue any_cast: opt-out instead opt-in

Now that we know LWG Defect 2509 has been accepted and C++17 compilers implement it, is there any reason linb::any_cast should continue adhering strictly to the N4562 proposal and keep opting-in to moving rvalues?

I would prefer to have the move-feature enabled by default and opt-out if at all necessary.

Clang build error on macOS: any.hpp: error: no matching 'operator new' function for non-allocating placement new expression; include <new>

In file included from /opt/local/var/macports/build/_Users_runner_work_macports-ports_macports-ports_ports_devel_any/any/work/any-bfc77f2e4be6e9a093dd645ef3f1aa30620c9205/test_shared_lib.hpp:3:
  /opt/local/var/macports/build/_Users_runner_work_macports-ports_macports-ports_ports_devel_any/any/work/any-bfc77f2e4be6e9a093dd645ef3f1aa30620c9205/any.hpp:279:13: error: no matching 'operator new' function for non-allocating placement new expression; include <new>
              new (&dest.stack) T(reinterpret_cast<const T&>(src.stack));
              ^~~

Full log: https://github.com/macports/macports-ports/actions/runs/3944844343/jobs/6751175466

Versioning/tags

Is it possible to version this impl of an any? Either with a branch or a tag? I've started using it and we prefer to be using versioned releases rather than the bleeding edge.

Passing across shared library boundary

It looks like the type checking is done by several function pointer comparisons (vtable). I've noticed that if I put a std::string in a linb::any in one dll, and try to extract it in another (even by reference), it always throws a bad_cast exception.

Digging into it, it looks like the vtable pointers are set for the std::string in the dll that sets the linb::any, but when I try to cast the std::string out, it fails because it creatse a new vtable in the casting dll.

Does it make sense to use type_info to compare types?

Update: I have not tested this in linux.

Missing #include <utility> for std::forward

/wrkdirs/usr/ports/multimedia/opentimelineio/work/OpenTimelineIO-0.14.1/src/deps/any/any.hpp:101:30: error: no member named 'forward' in namespace 'std'
        this->construct(std::forward<ValueType>(value));
                        ~~~~~^

Consider compilation for embedded platforms

Compilation for embedded platforms is typically missing exception handling and RTTI.
It would be nice to check the availability of those features like gcc does.

Furthermore, a different implementation of any_cast would solve the performance cost incurred by type_id comparisons.

See pull request #8

C++17 Interface

According to cppreference documentation (can't find the latest draft), the C++17 interface for std::any is a bit different from the one we are basing on, std::experimental::any. Function names changed and a few were added.

What should we do? Migrate to the new interface? Keep this?

Suggestions are very welcome.

Additional Info:

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.