Coder Social home page Coder Social logo

type_traits's Introduction

Boost TypeTraits Library

The Boost type-traits library contains a set of very specific traits classes, each of which encapsulate a single trait from the C++ type system; for example, is a type a pointer or a reference type? Or does a type have a trivial constructor, or a const-qualifier?

The type-traits classes share a unified design: each class inherits from the type true_type if the type has the specified property and inherits from false_type otherwise.

The type-traits library also contains a set of classes that perform a specific transformation on a type; for example, they can remove a top-level const or volatile qualifier from a type. Each class that performs a transformation defines a single typedef-member type that is the result of the transformation.

The full documentation is available on boost.org.

Master Develop
Travis Build Status Build Status
Appveyor Build status Build status

Support, bugs and feature requests

Bugs and feature requests can be reported through the Gitub issue tracker (see open issues and closed issues).

You can submit your changes through a pull request.

There is no mailing-list specific to Boost TypeTraits, although you can use the general-purpose Boost mailing-list using the tag [type_traits].

Development

Clone the whole boost project, which includes the individual Boost projects as submodules (see boost+git doc):

git clone https://github.com/boostorg/boost
cd boost
git submodule update --init

The Boost TypeTraits Library is located in libs/type_traits/.

Running tests

First, make sure you are in libs/type_traits/test. You can either run all the tests listed in Jamfile.v2 or run a single test:

../../../b2                        <- run all tests
../../../b2 config_info            <- single test

type_traits's People

Contributors

alnsn avatar apolukhin avatar beman avatar brycelelbach avatar dabrahams avatar danieljames avatar douggregor avatar ecatmur avatar eldiener avatar glenfe avatar grafikrobot avatar hkaiser avatar igaztanaga avatar jensmaurer avatar joaquintides avatar jsiek avatar jzmaddock avatar kivadiu avatar kojoley avatar kuhlenough avatar lastique avatar marcelraad avatar morinmorin avatar pdimov avatar sdarwin avatar steveire avatar straszheim avatar thorsten-ottosen avatar toonknapen avatar viboes 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

type_traits's Issues

Unqualified std type trait use?

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
# if __has_extension(is_trivially_constructible)
# define BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__is_trivially_constructible(T, T&&) && is_constructible<T, T&&>::value && !::boost::is_volatile<T>::value)
# endif
# if __has_extension(is_trivially_assignable)
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) (__is_trivially_assignable(T&, T&&) && is_assignable<T&, T&&>::value && !::boost::is_volatile<T>::value)
# endif
#endif

When I compile this with clang-cl on Windows, I get the following error (in Boost 1.68, but the code appears unchanged here):

T:\boost\boost_1_68_0\include\boost/type_traits/has_trivial_move_assign.hpp(49): error : no template named 'is_assignable'; did you mean 'std::is_assignable'?
T:\boost\boost_1_68_0\include\boost/type_traits/intrinsics.hpp(233): note: expanded from macro 'BOOST_HAS_TRIVIAL_MOVE_ASSIGN'

It does seem peculiar that this is being called unqualified here.

is_function_cxx_11.hpp(102): error C3193: '__clrcall': requires '/clr' or '/ZW' command line option

I'm trying to build an unmanaged project where I can't enable /clr, I upgraded the Boost libraries from v1.67 to 1.71, and keep getting this error for some files that uses boost:
>c:\..\..\thirdparty\source\boost\boost_1_71_0\boost\type_traits\detail\is_function_cxx_11.hpp(102): error C3193: '__clrcall': requires '/clr' or '/ZW' command line option
I tried to turn on the /clr option only for those specific files, but it becomes a whole mess with some project dependencies ..
Is there any solution or workaround for this?

Unable to use type_traits with Intel Compiler 16 (boost 1.67+)

Source Code:

#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>

float getSomeNumber()
{
  return 10.0;
}

int main(int argc, char** argv)
{
   std::string mystring("Hello: " + boost::lexical_cast<std::string>(getSomeNumber());
   std::cout << mystring << std::endl;
   return 0;
}

Intel Compiler 16:

 /boost/1.67.0/include/boost/type_traits/is_complete.hpp(45): warning #70: incomplete type is not allowed

       ok_tag<sizeof(T)> check_is_complete(int);
       detected during ....
       ...

/boost/1.67.0/include/boost/type_traits/is_complete.hpp(51): error: template instantiation resulted in unexpected function type of "boost::detail::ok_tag<1U> (int)" (the meaning of a name may have changed since the template declaration -- the type of the template is "boost::detail::ok_tag<sizeof(T)> (int)")
       ...

     detected during: 
        instantiation of "boost::detail::check_is_complete" based on template argument <void> at line 51
        instantiation of class "boost::is_complete<T> [with T=void]" at line 484 of "/Path/to/boost/include/boost/type_traits/is_convertible.hpp"
        ...
        instantiation of "Target boost::lexical_cast<Target, Source>(const Source &) [with Target=std::string, Source=float]" at line 11 of "boostTest.cc"

Various test failures uncovered during local testing

This is what I have (CI_SUPPRESS_KNOWN_ISSUES has been defined):

Cygwin g++ 6.3.0:

testing.capture-output ..\..\bin.v2\libs\type_traits\test\alignment_of_a2_test.test\gcc-cxx03-6.3.0\debug\alignment_of_a2_test.run
====== BEGIN OUTPUT ======
test\alignment_of_a2_test.cpp:95: The expression: "::boost::alignment_of<double>::value" had an invalid value (found 8, expected 4)
test\alignment_of_a2_test.cpp:98: The expression: "::boost::alignment_of< ::boost::long_long_type>::value" had an invalid value (found 8, expected 4)

EXIT STATUS: 2
====== END OUTPUT ======
testing.capture-output ..\..\bin.v2\libs\type_traits\test\alignment_of_test.test\gcc-cxx03-6.3.0\debug\alignment_of_test.run
====== BEGIN OUTPUT ======
test\alignment_of_test.cpp:90: The expression: "::boost::alignment_of<double>::value" had an invalid value (found 8, expected 4)
test\alignment_of_test.cpp:93: The expression: "::boost::alignment_of< ::boost::long_long_type>::value" had an invalid value (found 8, expected 4)

EXIT STATUS: 2
====== END OUTPUT ======

(same for c++11, 14, 1z)

Cygwin clang++ 4.0.1 -std=c++1z:

clang-linux.compile.c++.without-pth ..\..\bin.v2\libs\type_traits\test\has_nothrow_destructor_test.test\clang-linux-cxx1z-4.0.1\debug\has_nothrow_destructor_test.obj
In file included from test\has_nothrow_destructor_test.cpp:12:
test/test.hpp:210:9: warning: 'const' qualifier on reference type 'r_type' (aka'int &') has no effect [-Wignored-qualifiers]
typedef const r_type cr_type;
        ^~~~~~
test\has_nothrow_destructor_test.cpp:37:21: error: ISO C++1z does not allow dynamic exception specifications [-Wdynamic-exception-spec]
   ~throwing_base() throw(int);
                    ^~~~~~~~~~
test\has_nothrow_destructor_test.cpp:37:21: note: use 'noexcept(false)' instead
   ~throwing_base() throw(int);
                    ^~~~~~~~~~
                    noexcept(false)
1 warning and 1 error generated.

Appveyor has Cygwin:

https://github.com/boostorg/system/blob/develop/appveyor.yml#L25

Travis has clang++ 4:

https://github.com/boostorg/smart_ptr/blob/develop/.travis.yml#L479

non-constexpr integral_constant conversions

integral_constant has this conversion operator to mpl::integral_c:

operator const mpl::integral_c<T, val>& ()const
{
    static const char data[sizeof(long)] = { 0 };
    static const void* pdata = data;
    return *(reinterpret_cast<const mpl::integral_c<T, val>*>(pdata));
}

which unfortunately is not / cannot be constexpr. (The integral_constant<bool, meow> partial specialization has a similar conversion to lvalue mpl::bool_<meow>.) These conversions are used in the initialization of lots of constant data in Boost::math, which could otherwise have constant initialization but sadly currently has dynamic initialization since these conversions are not constexpr.

Is there any way these could be made constexpr conversions to avoid that dynamic initialization?

Trying to compile with MSVC for ARM fails

Trying to build boost-regex with vcpkg with arm-static-windows triplet (modified arm-windows with static linkage) fails with following errors:

C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(106): error C2953: 'boost::is_function<Ret(Args...)>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(36): note: see declaration of 'boost::is_function<Ret(Args...)>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(109): error C2953: 'boost::is_function<Ret(Args...)>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(36): note: see declaration of 'boost::is_function<Ret(Args...)>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(123): error C2953: 'boost::is_function<Ret(Args...) const>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(41): note: see declaration of 'boost::is_function<Ret(Args...) const>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(126): error C2953: 'boost::is_function<Ret(Args...) const>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(41): note: see declaration of 'boost::is_function<Ret(Args...) const>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(140): error C2953: 'boost::is_function<Ret(Args...) volatile>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(46): note: see declaration of 'boost::is_function<Ret(Args...) volatile>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(143): error C2953: 'boost::is_function<Ret(Args...) volatile>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(46): note: see declaration of 'boost::is_function<Ret(Args...) volatile>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(157): error C2953: 'boost::is_function<Ret(Args...) volatile const>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(51): note: see declaration of 'boost::is_function<Ret(Args...) volatile const>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(160): error C2953: 'boost::is_function<Ret(Args...) volatile const>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(51): note: see declaration of 'boost::is_function<Ret(Args...) volatile const>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(175): error C2953: 'boost::is_function<Ret(Args...) &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(58): note: see declaration of 'boost::is_function<Ret(Args...) &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(178): error C2953: 'boost::is_function<Ret(Args...) &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(58): note: see declaration of 'boost::is_function<Ret(Args...) &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(192): error C2953: 'boost::is_function<Ret(Args...) const &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(63): note: see declaration of 'boost::is_function<Ret(Args...) const &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(195): error C2953: 'boost::is_function<Ret(Args...) const &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(63): note: see declaration of 'boost::is_function<Ret(Args...) const &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(209): error C2953: 'boost::is_function<Ret(Args...) volatile &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(68): note: see declaration of 'boost::is_function<Ret(Args...) volatile &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(212): error C2953: 'boost::is_function<Ret(Args...) volatile &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(68): note: see declaration of 'boost::is_function<Ret(Args...) volatile &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(226): error C2953: 'boost::is_function<Ret(Args...) volatile const &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(73): note: see declaration of 'boost::is_function<Ret(Args...) volatile const &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(229): error C2953: 'boost::is_function<Ret(Args...) volatile const &>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(73): note: see declaration of 'boost::is_function<Ret(Args...) volatile const &>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(244): error C2953: 'boost::is_function<Ret(Args...) &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(80): note: see declaration of 'boost::is_function<Ret(Args...) &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(247): error C2953: 'boost::is_function<Ret(Args...) &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(80): note: see declaration of 'boost::is_function<Ret(Args...) &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(261): error C2953: 'boost::is_function<Ret(Args...) const &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(85): note: see declaration of 'boost::is_function<Ret(Args...) const &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(264): error C2953: 'boost::is_function<Ret(Args...) const &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(85): note: see declaration of 'boost::is_function<Ret(Args...) const &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(278): error C2953: 'boost::is_function<Ret(Args...) volatile &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(90): note: see declaration of 'boost::is_function<Ret(Args...) volatile &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(281): error C2953: 'boost::is_function<Ret(Args...) volatile &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(90): note: see declaration of 'boost::is_function<Ret(Args...) volatile &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(295): error C2953: 'boost::is_function<Ret(Args...) volatile const &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(95): note: see declaration of 'boost::is_function<Ret(Args...) volatile const &&>'
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(298): error C2953: 'boost::is_function<Ret(Args...) volatile const &&>': class template has already been defined
C:\Users\user\vcpkg\installed\arm-static-windows\include\boost/type_traits/detail/is_function_cxx_11.hpp(95): note: see declaration of 'boost::is_function<Ret(Args...) volatile const &&>'

You can find full log as provided by vcpkg here: https://gist.github.com/janisozaur/cf45cb9990da6044ef75621e9e104b3f

Add remove_member_pointer

template<class Pm> struct remove_member_pointer
{
    typedef Pm type;
};

template<class T, class C> struct remove_member_pointer<T C::*>
{
    typedef T type;
};

Warning C4575 when compiled as a C++/CLI .Net Core project with Visual Studio 2019 v16.8

If you include a boost header (such as boost/algorithm/string.hpp) that ultimately includes is_funcion_cxx_11.hpp in a C++/CLI .NET Core (NOT the normal .NET Framework) project, you will see a series of compiler warnings similar to the following:

boost-1.74\boost\type_traits\detail\is_function_cxx_11.hpp(114,4): warning C4575: '__vectorcall' incompatible with the '/clr' option: converting to '__stdcall'

struct is_function<Ret __vectorcall(Args...)BOOST_TT_NOEXCEPT_DECL> : public true_type {};

There is no warning here if the C++/CLI project is compiled as .NET Framework instead. It looks like __CLR_VER is defined when building as .NET Framework, but not when building as .NET Core?

How to convert your C++/CLI project to build as .NET Core (instead of the normal .NET Framework):
https://docs.microsoft.com/en-us/dotnet/core/porting/cpp-cli

Miss a ')' in the file boost/type_traits/is_empty.hpp

PC: Ubuntu 20.04
Boost: 1.71

Recently, I had met:

/usr/include/boost/type_traits/is_empty.hpp:78: Parenthesis/brace mismatch between #if and #else branches; using #if branch

2020-12-23 19-16-00屏幕截图

It was because of missing the ) of BOOST_STATIC_CONSTANT.
2020-12-23 19-14-34屏幕截图

===============================

I can not find this file in this github, so I open this issue.
Maybe this issue can do some help :)

is_function return false for cv-qualified function types

In fact it flat out fails to compile with msvc.

#include <boost/type_traits/is_function.hpp>
#include <boost/core/lightweight_test_trait.hpp>

struct X
{
    void f() {}
    void fc() const {}
    void fv() volatile {}
    void fcv() const volatile {}
};

template< class C, class F > void test( F C::* )
{
    BOOST_TEST_TRAIT_TRUE(( boost::is_function< F > ));
}

int main()
{
    test( &X::f );
    test( &X::fc );
    test( &X::fv );
    test( &X::fcv );

    return boost::report_errors();
}

Moved from https://svn.boost.org/trac10/ticket/10934

GCC 4.6 is_nothrow_move_assignable

I know that C++11 on GCC < 4.7 is awful, but true is not a good default if there is not way to determine noexceptness.

#include <boost/type_traits/is_nothrow_move_assignable.hpp>

struct foo
{
    foo& operator=(foo&&) noexcept(false) { throw 0; }
};

static_assert(!boost::is_nothrow_move_assignable<foo>::value, "");

https://godbolt.org/z/WT3g9q

function_traits doesn't support qualified function types

Add the moment function_traits works for void () noexcept, but not for void () const or void () &.

If we fix that, it would be a good opportunity to also add

{
    template<class...> struct list {};
    using arguments = list<A1, A2, ..., An>;
}

(on C++11) which can be further manipulated with Mp11. (The argN_type typedefs aren't generic.)

`is_function` breaks with noexcept function types in C++17

boost::is_function currently does not handle noexcept function types which is distinct from non-noexcept function types. e.g.

#include <boost/type_traits.hpp>
#include <type_traits>

void foo(int){}
void bar(int) noexcept{}

int main(){
    static_assert(boost::is_function<decltype(foo)>::value);
    static_assert(boost::is_function<decltype(bar)>::value);
    return 0;
}

Both GCC 7.2 and Clang 5.0 failed the second assertion if compiled with -std=c++1z flag.

Plus, boost::is_member_function_pointer has the same issue too.

Boost version is 1.65.1.

Injection of non-boost namespaces into global namespace

Like the global namespace injection in include/bind.hpp, this needs to begin being deprecated immediately and removed in a near future Boost as it causes symbol collision between incompatible Boosts:

boost/mpl/aux_/adl_barrier.hpp:#   define BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE mpl_
boost/mpl/aux_/adl_barrier.hpp:#   define BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN namespace mpl_ {
boost/type_traits/integral_constant.hpp:namespace mpl_{
boost/type_traits/integral_constant.hpp:      using ::mpl_::bool_;
boost/type_traits/integral_constant.hpp:      using ::mpl_::integral_c;
boost/type_traits/integral_constant.hpp:      using ::mpl_::integral_c_tag;

I get errors with latest version 69 and VS 2017

a lot of errors in packages\boost.1.69.0.0\lib\native\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp

Severity Code Description Project File Line Suppression State
Error C2764 'C': template parameter not used or deducible in partial specialization 'boost::is_member_function_pointer<Ret(Args...) volatile const &>' packages\boost.1.69.0.0\lib\native\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp 220

another error:
Severity Code Description Project File Line Suppression State
Error C2059 syntax error: 'generic' \packages\boost.1.69.0.0\lib\native\include\boost\filesystem\path.hpp 579

can someone help, thanks

Usage of boost::void_t

Boost 1.67.0+ uses boost::void_t<> in many traits, although it is only defined if BOOST_NO_CXX11_TEMPLATE_ALIASES is not defined.

This causes compile issues on platforms using those includes where template aliases are not available (or BOOST_NO_CXX11_TEMPLATE_ALIASES is set).

alignment_of_test is invalid (especially for IA32)

This test determines that the __alignof() operator returns the same value as an actual compiler alignment. However the __alignof (type) is suppose to return the minimal required alignment for the type, not the actual alignment the compiler uses. So on IA32 where an alignment of 1 works, and the ABI specifies a minimum of 4; __alignof(type) returns 4, which is correct. However in almost all cases the compiler will align at 8, for performance reasons and the test fails. On all other configs we tested the actual, and minimal alignment for clang 6.0 are the same.
Leading to misinformed comment here https://github.com/boostorg/type_traits/include/boost/type_traits/intrinsics.hpp#L289
and a fall-back of not using actual __alignof() operator for most of Boost's supported platforms.

decay strips cv-qualifiers

Since d3ac8b9 boost::decay strips cv-qualifiers, but the documentation was never adjusted accordingly:

Let U be the result of remove_reference<T>::type, then if U is an array type, the result is remove_extent<U>::type*, otherwise if U is a function type then the result is U*, otherwise the result is U.

is_base<T, T> is broken on MSVC10 when T is not defined

Currently on Windows with MSVC10 boost defines BOOST_IS_BASE_OF (which is used in is_base_and_derived, which is used in is_base_of) as follows:

#define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_same<T,U>::value)

But microsoft's intrinsic __is_base_of cannot be used with the same type (i.e. T = U) when it (the type) is not defined.

When the following is compiled

class A;
typedef typename boost::is_base_of<A, A>::type x;

you get an error message:

...\include\boost\type_traits\is_base_and_derived.hpp(228) : error C2139: 'A' : an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of'
...\include\boost\type_traits\is_base_of.hpp(29) : see reference to class template instantiation 'boost::detail::is_base_and_derived_impl<B,D>' being compiled
        with
        [
            B=A,
            D=A
        ]

The same code compiles on gcc-4.8.2 and clang-3.6.

Moved from https://svn.boost.org/trac10/ticket/11422

is_nothrow_move_constructible gives false positive in GCC 4.7.4

The following code assertion-fails on GCC 4.7:

#include <boost/type_traits.hpp>

struct X
{
  X(X&&) noexcept(false) { throw 0; }
};

X&& make_X() noexcept;

int main() 
{
  static_assert(!boost::is_nothrow_move_constructible<X>::value, "** 1");
  static_assert(!noexcept(X(make_X())), "** 2");
}

(see the failure online at https://wandbox.org/permlink/mTBxqXQED1ts34uF)

This is because the trait is expanded to:

template <class T>
struct is_nothrow_move_constructible
   : public integral_constant<bool,
   (::boost::has_trivial_move_constructor<T>::value || ::boost::has_nothrow_copy<T>::value) && !::boost::is_array<T>::value>
{};

And boost::has_nothrow_copy<T>::value works incorrectly on this compiler:

#include <boost/type_traits.hpp>

struct X
{
  X(X&&) = delete;
};

int main() 
{    
  static_assert(!::boost::has_nothrow_copy<X>::value, "** 2");
}

Boost 1.70.0 compile errors in VS2017 x86 /std:c++17 /clr

Hi,

I get compiler errors when trying to compile with 32 bit and CLR using Visual Studio 2017:

libraries\boost\type_traits\detail\is_function_cxx_11.hpp(388): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(388): error C2953: 'boost::is_function<Ret(Args...) noexcept>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(386): note: see declaration of 'boost::is_function<Ret(Args...) noexcept>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(403): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(403): error C2953: 'boost::is_function<Ret(Args...) noexcept const>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(401): note: see declaration of 'boost::is_function<Ret(Args...) noexcept const>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(418): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(418): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(416): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(433): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(433): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile const>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(431): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile const>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(449): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(449): error C2953: 'boost::is_function<Ret(Args...) noexcept &>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(447): note: see declaration of 'boost::is_function<Ret(Args...) noexcept &>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(464): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(464): error C2953: 'boost::is_function<Ret(Args...) noexcept const &>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(462): note: see declaration of 'boost::is_function<Ret(Args...) noexcept const &>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(479): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(479): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile &>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(477): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile &>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(494): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(494): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile const &>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(492): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile const &>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(510): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(510): error C2953: 'boost::is_function<Ret(Args...) noexcept &&>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(508): note: see declaration of 'boost::is_function<Ret(Args...) noexcept &&>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(525): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(525): error C2953: 'boost::is_function<Ret(Args...) noexcept const &&>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(523): note: see declaration of 'boost::is_function<Ret(Args...) noexcept const &&>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(540): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(540): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile &&>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(538): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile &&>'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(555): warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(555): error C2953: 'boost::is_function<Ret(Args...) noexcept volatile const &&>': class template has already been defined
libraries\boost\type_traits\detail\is_function_cxx_11.hpp(553): note: see declaration of 'boost::is_function<Ret(Args...) noexcept volatile const &&>'

compile error, boost_1_70_0_b1, C++17, MSVC 1916

we found Boost version 1.70.0 b1 not compiling against our code base with C++17 and MSVC version 1916 in conjunction with the /Zc:noexceptTypes- compiler flag. Resulting error is of type:

boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp(359): error C2953: 'boost::is_member_function_pointer<Ret(__cdecl C::* )(Args...)>': class template has already been defined
boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp(48): note: see declaration of 'boost::is_member_function_pointer<Ret(__cdecl C::* )(Args...)>'

has_nothrow_copy_test weirdly fails on msvc-12.0

====== BEGIN OUTPUT ======
test\has_nothrow_copy_test.cpp:243: The expression: "::boost::has_nothrow_copy<delete_move>::value" had an invalid value (found 1, expected 0)

EXIT STATUS: 1
====== END OUTPUT ======

I have define=CI_SUPPRESS_KNOWN_ISSUES on the command line. Interestingly, Appveyor passes.

I see

#if !(defined(CI_SUPPRESS_KNOWN_ISSUES) && BOOST_WORKAROUND(BOOST_GCC, < 40600)) && !(defined(CI_SUPPRESS_KNOWN_ISSUES) && BOOST_WORKAROUND(BOOST_MSVC, == 1800))

All right, this middle && probably needs to be ||, but why does Appveyor pass? It's a mystery.

`is_complete` is incorrect for reference types

is_complete<T&>::value is currently defined to be the value of is_complete<T>::value. This is incorrect. According to the standard, all lvalue reference types and rvalue reference types are complete types.

In [basic.types]:

A class that has been declared but not defined, an enumeration type in certain contexts (9.6), or an array of unknown bound or of incomplete element type, is an incompletely-defined object type. Incompletely-defined object types and cv void are incomplete types (6.7.1). Objects shall not be defined to have an incomplete type.

References do not fall under any of the above cases and are therefore complete.

Obsolete Mac configurations in Travis

The xcode8.2, xcode8.1 configurations say

 This job was configured to run on an OS X image that was retired on November 28, 2017. It was routed to our Xcode 8.3 image.

(but the 8.3 part is wrong and they actually use the default 9.4.)

xcode8.0 doesn't exist at all, and also falls back to the default. Should be xcode8.

xcode6.4 says

Running builds with Xcode 6.4 in Travis CI is deprecated and will be removed in January 2019.

See https://docs.travis-ci.com/user/reference/osx#os-x-version

Using boost 1.69 with /CLR (windows .net) fails

Triggers this error:

Warning	C4561	
'__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
...\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp	120	

Error	C2953	
'boost::is_member_function_pointer<Ret(__stdcall C::* )(Args...)>': class template has already been defined
...\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp	120	

The fix is attached.
clr_patch.txt

boost 1.69 doesn't compile with VS 2017 /clr

BoostConsole.zip

If you try to compile this with VS 2017 15.9.5 using boost 1.69 you get 60 errors and 48 warnings
(It does compile with boost 1.68)

Error C2764
'C': template parameter not used or deducible in partial specialization 'boost::is_member_function_pointer<Ret(Args...)>'
boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp 114

Warning C4561
'__fastcall' incompatible with the '/clr' option: converting to '__stdcall'
boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp 120

Error C2953
'boost::is_member_function_pointer<Ret(__stdcall C::* )(Args...)>': class template has already been defined
boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp 120
...

with best regards

Hendrik

Failures because of lack of CI_SUPPRESS_KNOWN_ISSUES

I've enhanced the superproject Appveyor (and Travis) to run the tests for the library updated in the commit:

https://ci.appveyor.com/project/boostorg/boost/build/1.0.3623

But type_traits fails because - I assume - CI_SUPPRESS_KNOWN_ISSUES isn't set.

Since this Appveyor support is generic and not specific to a library, I'd rather not include library-specific workarounds in it such as this one; so maybe the test Jamfile could detect Appveyor and Travis using for example [ os.environ CI ] and turn on the workarounds automatically?

compiler warning on 64bits gcc

Hi

File is_complete.hpp make warning in line 47:

  template <unsigned N>
  struct ok_tag { double d; char c[N]; };
  template <class T>
  ok_tag<sizeof(T)> check_is_complete(int);

specialization ok_tag<sizeof(T)> check_is_complete(int); make implicit cast from unsigned long long (size_t is unsigned long long on 64 arch) to unsigned (32bits) and ugly warning on output.
It may be easy overcome and make more portable by:

  template <size_t N>
  struct ok_tag { double d; char c[N]; };

Warnings after applying nodiscard to operators

I encountered this in Boost 1.68; I have not verified it in current Boost but I did manually inspect the relevant code and it appears to be unchanged, so I suspect the issue is still present.

If you apply the [[nodiscard]] attribute to various operators (such as operator== and operator+) -- as seems sensible as these are pure functions -- then VS2017 at least produces a warning that the return value is discarded:

t:\boost\boost_1_68_0\include\boost\type_traits\detail\has_binary_operator.hpp(149): warning C4834: discarding return value of function with 'nodiscard' attribute
t:\boost\boost_1_68_0\include\boost\type_traits\detail\has_binary_operator.hpp(233): note: see reference to class template instantiation 'boost::detail::has_equal_to_impl::operator_returns_void<Lhs,Rhs>' being compiled

(In my case this originated from a call to boost::has_equal_to and boost::has_less (and thus operator== and operator<), but it would presumably affect any other binary operator, and most likely other operator types as well.)

Most likely this just needs an explicit cast to void to silence the warning.

BOOST_WORKAROUND(__clang_major__, ...) generates an undefined preprocessor symbol

This code in config.hpp:

#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !BOOST_WORKAROUND(BOOST_GCC, < 40900)\
      && !BOOST_WORKAROUND(BOOST_MSVC, < 1900) && !BOOST_WORKAROUND(__clang_major__, <= 4)
#  define BOOST_TT_HAS_ASCCURATE_IS_FUNCTION
#endif

Can generate a warning or error as __clang_major___WORKAROUND_GUARD is not defined.

is_trivially_copyable doesn't follow the standard's definition

#include <boost/type_traits.hpp>
#include <type_traits>

struct foo {
  foo(foo const&) = delete; // deleted copy constructor
  foo& operator=(foo const&) = default;
};

struct bar {
  bar(bar const&) = default;
  bar(bar &&) {} // user defined move constructor
  auto operator=(bar const&) -> bar& = default;
  auto operator=(bar &&    ) -> bar& { return *this; } // user defined move assignment
};

static_assert(not boost::is_trivially_copyable<foo>::value);
static_assert(    std  ::is_trivially_copyable<foo>::value);

static_assert(    boost::is_trivially_copyable<bar>::value);
static_assert(not std  ::is_trivially_copyable<bar>::value);

https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable
types with deleted constructors/move assignment operators are allowed to be trivially copyable, as long as at least one of them is defined, and all the non deleted ones are trivial.

Add `is_trivial` and `is_trivially_copyable`

Boost.TypeTraits is missing traits is_trivial and is_trivially_copyable. It is very tricky to implement them using has_trivial_constructor and others. It would be really useful to have is_trivial which degrades to is_pod on older compilers and is std::is_trivial on the newer.

warnings/errors compiling with /clr option in msvc

As someone else reported in the mailing list:

1>c:\quinesoftwarebase\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp(114):
error C2764: 'C': template parameter not used or deducible in partial
specialization 'boost::is_member_function_pointer<Ret(Args...)>'
1>c:\quinesoftwarebase\include\boost\type_traits\detail\is_member_function_pointer_cxx_11.hpp(125):
warning C4575: '__vectorcall' incompatible with the '/clr' option:
converting to '__stdcall'

Basically the __clrcall variant isn't using the C template parameter, so I adjusted them to match the other calling convention variants.

Several calling conventions exist/do not exist/default differently based on x86/x64 settings and enabling CLR so adjusted the #if logic accordingly.

I've adjusted these files to deal with the problems; provided to assist:

https://1drv.ms/f/s!Auh9GRj1YtuPuP545hS6BPhF0apLzQ

is_base_of for template base

is_base_of provides functionality to check whether a particular type is inherited from another particular type or not. But when the parent class is a templated class and want to check if the given type is inherited from any instance of the template it becomes hard to do it with is_base_of. Consider the example below:

template<typename X>
class base{};

class derived: public base<int>{};

now if I want to use is_base_of with this hierarchy it would look something like:

boost::is_base_of<base<X>, derived>::value;

and here X needs to be specified every time. But I would like to propose a way in which we don't need to specify the X and we can omit the base template argument and check general instance of the base.

So if this seems good then I would like to submit the pull request for the same.

Boost 1.70.0 compile errors in VS2019 ARM64 /std:c++17

It's similar to #118, but not exactly the same. When including the headers of type_traits, the error messages are:
.../boost/type_traits/detail/is_function_cxx_11.hpp(386): error C2953: 'boost::is_function<Ret(Args...) noexcept>': class template has already been defined
.../boost/type_traits/detail/is_function_cxx_11.hpp(316): note: see declaration of 'boost::is_function<Ret(Args...) noexcept>'
...

Looks like the compiler takes __cdecl, __stdcall, and __fastcall the same thing.

Fix for gccxml

We use gccxml (some deprecated gcc to XML tool relying on old gcc, e.g. 4.9.3, versions) for code generation and encountered a problem when including boost/type_traits.hpp from newer boost versions. The expression for getting the result_type size of the common type of T() and U() somehow generated illegal "node identifiers" for gccxml.

I'm not sure if this is really worth fixing, but it worked for older boost versions and the following workaround fixes the issue for us:

diff -rpu boost_1_66_0_old/boost/type_traits/detail/common_arithmetic_type.hpp boost_1_66_0/boost/type_traits/detail/common_arithmetic_type.hpp
--- boost_1_66_0_old/boost/type_traits/detail/common_arithmetic_type.hpp	2017-12-14 00:56:49.000000000 +0100
+++ boost_1_66_0/boost/type_traits/detail/common_arithmetic_type.hpp	2018-04-26 14:14:44.020680512 +0200
@@ -205,10 +205,11 @@ private:
 #endif
 
     static bool cond();
+    static const int selector = sizeof(select( cond()? T(): U() ));
 
 public:
 
-    typedef typename arithmetic_type< sizeof(select( cond()? T(): U() )) >::type type;
+    typedef typename arithmetic_type< selector >::type type;
 };
 
 } // namespace type_traits_detail

`is_final` doesn't work with template types on gcc 6.4.0

For this code:

#include <boost/type_traits/is_final.hpp>
#include <type_traits>
#include <iostream>

struct final1 final {};
template <typename T> struct final2 final {};

int main() {
    std::cout << "boost::is_final<final1>: " << boost::is_final<final1>::value << std::endl;
    std::cout << "boost::is_final<final2<int>>::value: " << boost::is_final<final2<int>>::value << std::endl;
    std::cout << "std::is_final<final1>: " << std::is_final<final1>::value << std::endl;
    std::cout << "std::is_final<final2<int>>::value: " << std::is_final<final2<int>>::value << std::endl;
}

GCC 6.4.0 outputs:

boost::is_final<final1>: 1
boost::is_final<final2<int>>::value: 0
std::is_final<final1>: 1
std::is_final<final2<int>>::value: 1

I'd expect all values to be 1. I get that for Clang.

is_member_func_test fails for GCC 4.8.1

is_member_func_test fails for GCC 4.8.1 as shown in

https://www.boost.org/development/tests/master/developer/output/igaztanaga-master-gcc-4-8c++11-boost-bin-v2-libs-type_traits-test-is_member_func_test-test-gcc-4-8c+-dbg-dbg-symbl-off-vsblt-hdn.html

The problem here is that is_member_function_pointer.hpp dispatches to a C++11 implementation or a C++03 one depending on whether BOOST_TT_HAS_ASCCURATE_IS_FUNCTION is defined or not:

#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !BOOST_WORKAROUND(BOOST_GCC, <= 40800)\
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1900) && !BOOST_WORKAROUND(__clang_major__, <= 4)
# define BOOST_TT_HAS_ASCCURATE_IS_FUNCTION
#endif

And BOOST_GCC is 40801 for the offending compiler. I guess the fix is as simple as changing BOOST_WORKAROUND(BOOST_GCC, <= 40800) to BOOST_WORKAROUND(BOOST_GCC, < 40900).

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.