GithubHelp home page GithubHelp logo

any's People

Contributors

alnsn avatar apolukhin avatar beman avatar dabrahams avatar danieljames avatar douggregor avatar eldiener avatar fanquake avatar giomasce avatar grafikrobot avatar imikejackson avatar jensmaurer avatar jzmaddock avatar luzpaz avatar marcelraad avatar mike-devel avatar pdimov avatar rarutyun avatar sdarwin avatar steveire avatar straszheim avatar swatanabe avatar vprus 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

any's Issues

Type casting short hand

Please implement the below

template <typename ValueType>
constexpr operator ValueType() const {return boost::any_cast<ValueType>(*this);}

As it makes the code look nicer

std::string foo = "Hello World!\n";
boost::any value = foo;
std::cout << (std::string)value;

GCC suggest-override warnings

Complete list of warnings when Boost 1.72 is built with GCC 7.5 with -Wsuggest-override added to cxxflags. Duplicated warnings from same location are omitted::

./boost/any.hpp:190:56: warning: ‘const type_info& boost::any::holder::type() const [with ValueType = bool; boost::typeindex::type_info = std::type_info]’ can be marked override [-Wsuggest-override]
./boost/any.hpp:195:35: warning: ‘boost::any::placeholder* boost::any::holder::clone() const [with ValueType = bool]’ can be marked override [-Wsuggest-override]
./boost/any.hpp:241:30: warning: ‘virtual const char* boost::bad_any_cast::what() const’ can be marked override [-Wsuggest-override]

BOOST_OVERRIDE was introduced in boostorg/config@ffe4e0f.

UBSAN related to any and visibility

This is from the mailing list, with an excellent summary from @pdimov :

Chris Rorvick wrote:

I am seeing my GCC ubsan builds littered with "downcast of address
xxxxxxxx which does not point to an object of type 'holder'" errors [3]
coming from Boost.Program_options (Boost 1.69). The issue has been
documented in various places [1][2] but I do not see anything on the
mailing list in recent months; apologies if I have missed something.

A workaround is proposed on the StackOverflow post [1]. Does anyone have
any thoughts on this?

Many thanks!

Chris

[1]
https://stackoverflow.com/questions/38987728/why-does-boostany-exhibit-undefined-behaviour-in-boostprogram-options
[2] boostorg/program_options#76
[3]
.../boost/boost/any.hpp:249:17: runtime error: downcast of address
0x602000053610 which does not point to an object of type 'holder'
0x602000053610: note: object is of type 'boost::any::holderstd::string'
6f 00 80 67 d0 91 ec 88 fe 7f 00 00 68 33 09 00 40 60 00 00 00 00
00 00 00 00 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'boost::any::holderstd::string'
...

This doesn't seem to be the same issue as in the SO link. The cv qualifiers
are now being stripped by the constructor at

https://github.com/boostorg/any/blob/develop/include/boost/any.hpp#L49

twice (once by decay and once by remove_cv for added safety) and in your
message the held object is non-const:

note: object is of type 'boost::any::holderstd::string'

My guess is that holder needs BOOST_SYMBOL_VISIBLE. That is,

template<typename ValueType>
class holder : public placeholder

at
https://github.com/boostorg/any/blob/develop/include/boost/any.hpp#L168-L169
needs to be

template<typename ValueType>
class BOOST_SYMBOL_VISIBLE holder : public placeholder

Boost.Any allocator support RFC

Right now it is possible to use Boost.Any with types that require special alignment (sse intrinsics, Eigen3 data types, ...) by overriding the global operators new and delete. This solution is far from optimal, since it results in everything in the whole program being overaligned.

I'm opening this Request For Comments to discuss a possibly better solution to this problem.

The gist of the idea is for Boost.Any to store a polymorphic allocator (of possibly zero size), such that the user can provide an allocator when initializing/assigning/copying an any object.

This increases the API of Boost.Any (changes proposed below). It also decreases its performance, since allocating/deallocating memory would incur an extra virtual function call. It might also increase the size of the any object. One has, however, to consider the impact of the current workarounds in larger programs. Over-aligning all allocations might have a larger impact on performance and memory footprint than the proposed changes.

I think the following interface should be enough:

    any(polymorphic_allocator allocator = default_allocator()); 

    any(const any &, polymorphic_allocator allocator = default_allocator()); 

    any(any &&, polymorphic_allocator allocator = default_allocator()); 

    template<typename ValueType> any(const ValueType &, polymorphic_allocator allocator = default_allocator()); 

    template<typename ValueType> any(ValueType &&, polymorphic_allocator allocator = default_allocator()); 

Issue imported from https://svn.boost.org/trac10/ticket/11045
Reported by: gonzalobg88@…

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.