C++11中头文件type_traits介绍
C++11中的头文件type_traits定义了一系列模板类,在编译期获得某一参数、某一变量、某一个类等等类型信息,主要做静态检查。
此头文件包含三部分:
(1).Helper类:帮助创建编译时常量的标准模板类。介绍见以下测试代码:
template <unsigned n>
struct factorial : std::integral_constant<int, n * factorial<n - 1>::value> {};template <>
struct factorial<0> : std::integral_constant<int, 1> {};constexpr unsigned test_integral_constant() noexcept { return factorial<5>::value; }
static_assert(test_integral_constant() == 120, "value should be 120");// reference: https://stackoverflow.com/questions/58694521/what-is-stdfalse-type-or-stdtrue-type
struct true_type {static constexpr bool value = true;constexpr operator bool() const noexcept { return value; }// ...
};struct false_type {static constexpr bool value = false;constexpr operator bool() const noexcept { return value; }// ...
};int test_type_traits_helper_classes()
{// std::integral_constant: 编译时将常量作为类型,一般用做trait type的基类static_assert(factorial<5>::value == 120, "value should be 120");fprintf(stdout, "result: %u\n", factorial<5>::value); // constexpr(no calculations on runtime)// std::true_type: ==> std::integral_constant<bool, true>, 实例化integral_constant用以表示布尔值truestatic constexpr bool value1 = true;static_assert(std::integral_constant<bool, value1>::value == true, "value should be true");// std::false_type: ==> std::integral_constant<bool, false>, 实例化integral_constant用以表示布尔值falsestatic constexpr bool value2 = false;static_assert(std::integral_constant<bool, value2>::value == false, "value should be false");return 0;
}
(2).类型特征(Type traits):以编译时常量值的形式获取类型特征(characteristics of types)的模板类。介绍见以下测试代码:
int func(int i) { return i; }
class A { public: void func() {} };
struct B { int func(int a) { return a; } };
union C { int i; float f; };
enum class D { x, y, z };
struct F { int a; };
struct G { virtual void func() = 0; };
struct H { virtual void func() {} };
struct I : G { void func() override {} };
struct J { ~J() {} };
struct K { int x; K(const K& k) : x(k.x){}; };
struct L { virtual ~L() {} };
struct M { M& operator=(M&&) = delete; };
struct N { N& operator=(const A&) { return *this; } };
struct P { P(int) {} };
struct Q { ~Q() = delete; };
struct R : B { };
struct S {};int test_type_traits_type_traits()
{// 1.Primary type categories// std::is_array: T是不是数组类型,注意:此函数不会将数组类模板的实例化视为数组类型static_assert(std::is_array<A>::value == false, "");static_assert(std::is_array<A[3]>::value == true, "");static_assert(std::is_array<std::array<int, 3>>::value == false, "");// std::is_class: T是不是类类型static_assert(std::is_class<A>::value == true, "");static_assert(std::is_class<B>::value == true, "");static_assert(std::is_class<int>::value == false, "");// std::is_enum: T是不是枚举类型static_assert(std::is_enum<D>::value == true, "");static_assert(std::is_enum<A>::value == false, "");// std::is_floating_point: T是不是浮点类型static_assert(std::is_floating_point<float>::value == true, "");static_assert(std::is_floating_point<float&>::value == false, "");static_assert(std::is_floating_point<const double>::value == true, "");// std::is_function: T是不是函数类型static_assert(std::is_function<decltype(func)>::value == true, "");static_assert(std::is_function<int(int)>::value == true, "");// std::is_integral: T是不是整数类型static_assert(std::is_integral<const int>::value == true, "");static_assert(std::is_integral<bool>::value == true, "");static_assert(std::is_integral<char>::value == true, "");// std::is_lvalue_reference: T是不是左值引用类型static_assert(std::is_lvalue_reference<const A&>::value == true, "");static_assert(std::is_lvalue_reference<const A&&>::value == false, "");// std::is_rvalue_reference: T是不是右值引用类型static_assert(std::is_rvalue_reference<const A&>::value == false, "");static_assert(std::is_rvalue_reference<const A&&>::value == true, "");// std::is_member_function_pointer: T是不是非静态成员函数指针类型void(A::*pt)() = &A::func;static_assert(std::is_member_function_pointer<decltype(pt)>::value == true, "");static_assert(std::is_member_function_pointer<void(B::*)()>::value == true, "");static_assert(std::is_member_function_pointer<A*>::value == false, "");// std::is_member_object_pointer: T是不是非静态成员数据指针类型int F::* pt2 = &F::a;static_assert(std::is_member_object_pointer<decltype(pt2)>::value == true, "");static_assert(std::is_member_object_pointer<int F::*>::value == true, "");// std::is_pointer: T是不是指针类型static_assert(std::is_pointer<int*>::value == true, "");static_assert(std::is_pointer<int**>::value == true, "");static_assert(std::is_pointer<int(*)(int)>::value == true, "");// std::is_union: T是不是联合体类型static_assert(std::is_union<C>::value == true, "");static_assert(std::is_union<A>::value == false, "");// std::is_void: T是不是void类型static_assert(std::is_void<void>::value == true, "");static_assert(std::is_void<A>::value == false, "");// 2.Composite type categories: 复合类型// std::is_arithmetic: T是不是算术类型static_assert(std::is_arithmetic<char>::value == true, "");static_assert(std::is_arithmetic<char*>::value == false, "");// std::is_compound: T是不是复合类型,即不是基础类型static_assert(std::is_compound<char>::value == false, "");static_assert(std::is_compound<char*>::value == true, "");static_assert(std::is_compound<char&>::value == true, "");// std::is_fundamental: T是不是基础类型static_assert(std::is_fundamental<char>::value == true, "");static_assert(std::is_fundamental<char*>::value == false, "");static_assert(std::is_fundamental<void>::value == true, "");// std::is_member_pointer: T是不是非静态成员指针类型int F::* pt3 = &F::a;static_assert(std::is_member_pointer<int F::*>::value == true, "");static_assert(std::is_member_pointer<decltype(pt3)>::value == true, "");static_assert(std::is_member_pointer<void(B::*)()>::value == true, "");// std::is_object: T是不是对象类型,除函数、引用、void之外的所有类型static_assert(std::is_object<float>::value == true, "");static_assert(std::is_object<float&>::value == false, "");static_assert(std::is_object<int(int)>::value == false, "");static_assert(std::is_object<int(*)(int)>::value == true, "");// std::is_reference: T是不是引用类型,左值引用或右值引用static_assert(std::is_reference<int&>::value == true, "");static_assert(std::is_reference<int&&>::value == true, "");// std::is_scalar: T是不是标量类型,基础类型static_assert(std::is_scalar<int&>::value == false, "");static_assert(std::is_scalar<int*>::value == true, "");static_assert(std::is_scalar<A>::value == false, "");// 3.Type properties// std::is_abstract: T是不是抽象类static_assert(std::is_abstract<G>::value == true, "");static_assert(std::is_abstract<H>::value == false, "");static_assert(std::is_abstract<I>::value == false, "");// std::is_const: T是不是const限定类型static_assert(std::is_const<const int>::value == true, "");static_assert(std::is_const<const int*>::value == false, "");static_assert(std::is_const<int* const>::value == true, "");// std::is_empty: T是不是空类,空类是不存储任何数据的类,即没有非静态数据成员、没有虚函数、也没有虚基类static_assert(std::is_empty<F>::value == false, "");static_assert(std::is_empty<A>::value == true, "");static_assert(std::is_empty<H>::value == false, "");// std::is_literal_type: T是不是literal类型,可视为constexpr类型,标量、引用、certain 类,以及这些类型的数组都是literal类型static_assert(std::is_literal_type<A>::value == true, "");static_assert(std::is_literal_type<D>::value == true, "");static_assert(std::is_literal_type<J>::value == false, "");// std::is_pod: T是不是POD(Plain Old Data)类型,C语言支持的数据类型,若是类,它需要是trial(普通的)和standard-layoutstatic_assert(std::is_pod<A>::value == true, "");static_assert(std::is_pod<G>::value == false, "");static_assert(std::is_pod<J>::value == false, "");// std::is_polymorphic: T是不是多态类static_assert(std::is_polymorphic<A>::value == false, "");static_assert(std::is_polymorphic<G>::value == true, "");static_assert(std::is_polymorphic<I>::value == true, "");// std::is_signed: T是不是有符号算术类型static_assert(std::is_signed<A>::value == false, "");static_assert(std::is_signed<char>::value == true, "");static_assert(std::is_signed<int&>::value == false, "");// std::is_standard_layout: T是不是standard layout类型,如标量;若是类,则要求没有虚函数、虚基类、// 所有的非静态数据成员都具有相同的访问权限、在派生类中没有非静态数据成员static_assert(std::is_standard_layout<int>::value == true, "");static_assert(std::is_standard_layout<C>::value == true, "");static_assert(std::is_standard_layout<H>::value == false, "");// std::is_trivial: T是不是trivial(普通的)类型,如标量,存储连续;若是类,要求是默认构造/拷贝/移动拷贝/析构,没有虚成员static_assert(std::is_trivial<float>::value == true, "");static_assert(std::is_trivial<C>::value == true, "");static_assert(std::is_trivial<F>::value == true, "");// std::is_trivially_copyable: T是不是普通的拷贝类型,如标量;若是类,要求使用隐式定义的拷贝/移动函数、析构函数,没有虚成员#ifdef _MSC_VERstatic_assert(std::is_trivially_copyable<unsigned int>::value == true, "");static_assert(std::is_trivially_copyable<C>::value == true, "");static_assert(std::is_trivially_copyable<K>::value == false, "");#endif// std::is_unsigned: T是不是无符号算术类型static_assert(std::is_unsigned<unsigned int>::value == true, "");static_assert(std::is_unsigned<double>::value == false, "");// std::is_volatile: T是不是volatile-qualified类型static_assert(std::is_volatile<unsigned int>::value == false, "");static_assert(std::is_volatile<volatile int>::value == true, "");static_assert(std::is_volatile<volatile int*>::value == false, "");static_assert(std::is_volatile<int* volatile>::value == true, "");// 4.Type features// std::has_virtual_destructor: T是不是具有虚析构函数的类static_assert(std::has_virtual_destructor<A>::value == false, "");static_assert(std::has_virtual_destructor<L>::value == true, "");// std::is_assignable: U是不是赋值给T的类型; std::is_copy_assignable/std::is_move_assignable: T是不是拷贝/移动赋值类型static_assert(std::is_assignable<N, A>::value == true, "");static_assert(std::is_assignable<A, N>::value == false, "");static_assert(std::is_copy_assignable<int>::value == true, "");static_assert(std::is_copy_assignable<L>::value == true, "");static_assert(std::is_copy_assignable<M>::value == false, "");static_assert(std::is_move_assignable<L>::value == true, "");static_assert(std::is_move_assignable<M>::value == false, "");// std::is_constructible: 使用指定的参数,T是不是可构造类型// std::is_copy_constructible/std::is_default_constructible/std::is_move_constructible: T是不是拷贝构造/默认构造/移动构造类型static_assert(std::is_constructible<int>::value == true, "");static_assert(std::is_constructible<P, int>::value == true, "");static_assert(std::is_constructible<P, int, int>::value == false, "");static_assert(std::is_copy_constructible<M>::value == false, "");static_assert(std::is_copy_constructible<P>::value == true, "");static_assert(std::is_default_constructible<P>::value == false, "");static_assert(std::is_default_constructible<L>::value == true, "");static_assert(std::is_move_constructible<L>::value == true, "");static_assert(std::is_move_constructible<M>::value == false, "");// std::is_destructible: T是不是destructible类型,其析构函数不会被删除,且在派生类中是可访问的static_assert(std::is_destructible<int>::value == true, "");static_assert(std::is_destructible<L>::value == true, "");static_assert(std::is_destructible<Q>::value == false, "");#ifdef _MSC_VERstatic_assert(std::is_trivially_assignable<F, F>::value == true, "");static_assert(std::is_trivially_constructible<F>::value == true, "");static_assert(std::is_trivially_destructible<J>::value == false, "");#endifstatic_assert(std::is_nothrow_assignable<F, F>::value == true, "");static_assert(std::is_nothrow_constructible<F>::value == true, "");static_assert(std::is_nothrow_destructible<J>::value == true, "");// 5.Type relationships// std::is_base_of: 判断基类是不是派生类的基类static_assert(std::is_base_of<int, int>::value == false, "");static_assert(std::is_base_of<G, I>::value == true, "");static_assert(std::is_base_of<I, G>::value == false, "");// std::is_convertible: 判断From是不是可以隐式转换到Tostatic_assert(std::is_convertible<int, double>::value == true, "");static_assert(std::is_convertible<B, R>::value == false, "");static_assert(std::is_convertible<R, B>::value == true, "");// std::is_same: 判断U和T是不是属于相同的类型,当且仅当一个是另一种的typedef时,才认为两个不同的类型名代表相同的类型static_assert(std::is_same<int, const int>::value == false, "");typedef int integer_type;static_assert(std::is_same<int, integer_type>::value == true, "");typedef R R1;static_assert(std::is_same<R1, R>::value == true, "");// 6.Property queries// std::alignment_of: 返回类型T的对齐值static_assert(std::alignment_of<int>::value == 4, "");static_assert(std::alignment_of<S>::value == 1, "");static_assert(std::alignment_of<H*>::value == 8, "");// std::extent: 获取类型T第i维的范围typedef int mytype[][24][60];static_assert(std::extent<mytype, 0>::value == 0, "");static_assert(std::extent<mytype, 1>::value == 24, "");static_assert(std::extent<mytype, 2>::value == 60, "");static_assert(std::extent<mytype, 3>::value == 0, "");return 0;
}
(3).类型转换(Type transformations):通过对现有类型进行特定的转换来获取新类型的模板类。介绍见以下测试代码:
int test_type_traits_type_transformations()
{// 1.Const-volatile qualifications// std::add_const/std::remove_const: 对类型T添加/移除const限定符typedef std::add_const<int>::type Ax; // const inttypedef std::add_const<const int>::type Bx; // const int(unchanged)typedef std::add_const<const int*>::type Cx; // const int* consttypedef std::add_const<int* const>::type Dx; // int* const(unchanged)typedef std::add_const<const int&>::type Ex; // const int&(unchangedstatic_assert(std::is_const<Ax>::value == true, "");static_assert(std::is_const<Bx>::value == true, "");static_assert(std::is_const<Cx>::value == true, "");static_assert(std::is_const<Dx>::value == true, "");static_assert(std::is_const<Ex>::value == false, "");typedef std::remove_const<const char>::type Fx;static_assert(std::is_same<char, Fx>::value == true, "");// std::add_cv/std::remove_cv: 对类型T添加/移除const volatile限定符typedef std::add_cv<int>::type Ay;typedef std::add_cv<const int>::type By;typedef std::add_cv<volatile int>::type Cy;typedef std::add_cv<const volatile int>::type Dy;static_assert(std::is_same<const volatile int, Ay>::value == true, "");static_assert(std::is_same<const volatile int, By>::value == true, "");static_assert(std::is_same<const volatile int, Cy>::value == true, "");static_assert(std::is_same<const volatile int, Dy>::value == true, "");typedef std::remove_cv<const volatile char>::type Fy;static_assert(std::is_same<char, Fy>::value == true, "");// std::add_volatile/std::remove_volatile: 对类型T添加/移除volatile限定符typedef std::add_volatile<int>::type Az; // volatile inttypedef std::add_volatile<volatile int>::type Bz; // volatile int(unchanged)typedef std::add_volatile<int* volatile>::type Cz; // int* volatile(unchanged)typedef std::add_volatile<volatile int*>::type Dz; // volatile int* volatiletypedef std::add_volatile<volatile int&>::type Ez; // volatile int&(unchanged)static_assert(std::is_volatile<Az>::value == true, "");static_assert(std::is_volatile<Bz>::value == true, "");static_assert(std::is_volatile<Cz>::value == true, "");static_assert(std::is_volatile<Dz>::value == true, "");static_assert(std::is_volatile<Ez>::value == false, "");typedef std::remove_volatile<volatile char>::type Fz;static_assert(std::is_same<char, Fz>::value == true, "");// 2.Compound type alterations// std::add_pointer/std::remove_pointer: 获取/移除T的指针类型typedef std::add_pointer<int>::type Ap; // int*typedef std::add_pointer<const int>::type Bp; // const int*typedef std::add_pointer<int&>::type Cp; // int*typedef std::add_pointer<int*>::type Dp; // int**typedef std::add_pointer<int(int)>::type Ep; // int(*)(int)static_assert(std::is_same<int*, Ap>::value == true, "");static_assert(std::is_same<const int*, Bp>::value == true, "");static_assert(std::is_same<int*, Cp>::value == true, "");static_assert(std::is_same<int**, Dp>::value == true, "");static_assert(std::is_same<int*, Ep>::value == false, "");typedef std::remove_pointer<int**>::type Fp;static_assert(std::is_same<int*, Fp>::value == true, "");// std::add_lvalue_reference/std::add_rvalue_reference:获取T左值/右值引用类型;std::remove_reference: 获取T非引用类型typedef std::add_lvalue_reference<int>::type Aq; // int&typedef std::add_lvalue_reference<int&>::type Bq; // int&typedef std::add_lvalue_reference<int&&>::type Cq; // int&typedef std::add_lvalue_reference<int*>::type Dq; // int*&static_assert(std::is_same<int&, Aq>::value == true, "");static_assert(std::is_same<int&, Bq>::value == true, "");static_assert(std::is_same<int&, Cq>::value == true, "");static_assert(std::is_same<int&, Dq>::value == false, "");typedef std::add_rvalue_reference<int>::type Ar; // int&&typedef std::add_rvalue_reference<int&>::type Br; // int& (no change)typedef std::add_rvalue_reference<int&&>::type Cr; // int&& (no change)typedef std::add_rvalue_reference<int*>::type Dr; // int*&&static_assert(std::is_same<int&&, Ar>::value == true, "");static_assert(std::is_same<int&&, Br>::value == false, "");static_assert(std::is_same<int&&, Cr>::value == true, "");static_assert(std::is_same<int&&, Dr>::value == false, "");typedef std::remove_reference<int&>::type Fq;typedef std::remove_reference<int&&>::type Fr;static_assert(std::is_same<int, Fq>::value == true, "");static_assert(std::is_same<int, Fr>::value == true, "");// std::decay: 获得T的decay(退化)类型typedef std::decay<int>::type As; // inttypedef std::decay<int&>::type Bs; // inttypedef std::decay<int&&>::type Cs; // inttypedef std::decay<const int&>::type Ds; // inttypedef std::decay<int[2]>::type Es; // int*typedef std::decay<int(int)>::type Fs; // int(*)(int)static_assert(std::is_same<int, As>::value == true, "");static_assert(std::is_same<int, Bs>::value == true, "");static_assert(std::is_same<int, Cs>::value == true, "");static_assert(std::is_same<int, Ds>::value == true, "");static_assert(std::is_same<int, Es>::value == false, "");static_assert(std::is_same<int, Fs>::value == false, "");// std::make_signed/std::make_unsigned: 获取与T对应的带符号/无符号类型,并保留所有cv限定符typedef std::make_signed<int>::type At; // inttypedef std::make_signed<unsigned>::type Bt; // inttypedef std::make_signed<const unsigned>::type Ct; // const intstatic_assert(std::is_same<int, At>::value == true, "");static_assert(std::is_same<int, Bt>::value == true, "");static_assert(std::is_same<int, Ct>::value == false, "");typedef std::make_unsigned<int>::type Au; // unsigned intstatic_assert(std::is_same<unsigned, Au>::value == true, "");// std::remove_all_extents/std::remove_extent: 移除所有/数组范围typedef std::remove_all_extents<int>::type Av; // inttypedef std::remove_all_extents<int[24]>::type Bv; // inttypedef std::remove_all_extents<int[24][60]>::type Cv; // inttypedef std::remove_all_extents<int[][60]>::type Dv; // inttypedef std::remove_all_extents<const int[10]>::type Ev; // const intstatic_assert(std::is_same<int, Av>::value == true, "");static_assert(std::is_same<int, Bv>::value == true, "");static_assert(std::is_same<int, Cv>::value == true, "");static_assert(std::is_same<int, Dv>::value == true, "");static_assert(std::is_same<int, Ev>::value == false, "");typedef std::remove_extent<int[24][60]>::type Cw; // int[60]typedef std::remove_extent<int[][60]>::type Dw; // int[60]static_assert(std::is_same<int, Cw>::value == false, "");static_assert(std::is_same<int, Dw>::value == false, "");// std::underlying_type: 获取枚举类型T的基础类型enum class Aa { a, b, c };enum Ba : short { x, y, z };typedef std::underlying_type<Aa>::type A_under; // inttypedef std::underlying_type<Ba>::type B_under; // shortstatic_assert(std::is_same<int, A_under>::value == true, "");static_assert(std::is_same<int, B_under>::value == false, "");// 3.Other type generators// std::aligned_storage: 将内存分配与对象创建分离时使用// std::aligned_union: Obtains a POD type suitable for use as storage for any object whose type is listed in Types, and a size of at least Len// std::common_type: 在类型列表中获取所有类型都可以转换为的通用类型typedef std::common_type<char, short, int>::type Ab; // inttypedef std::common_type<float, double>::type Bb; // doubletypedef std::common_type<R, B>::type Cb; // Btypedef std::common_type<const int, volatile int>::type Db; // intstatic_assert(std::is_same<int, Ab>::value == true, "");static_assert(std::is_same<int, Bb>::value == false, "");static_assert(std::is_same<int, Cb>::value == false, "");static_assert(std::is_same<int, Db>::value == true, "");// std::conditional: 根据cond是true还是false,获取成员类型typedef std::conditional<true, int, float>::type Ac; // inttypedef std::conditional<false, int, float>::type Bc; // floattypedef std::conditional<std::is_integral<Ac>::value, long, int>::type Cc; // longtypedef std::conditional<std::is_integral<Bc>::value, long, int>::type Dc; // intstatic_assert(std::is_same<int, Ac>::value == true, "");static_assert(std::is_same<int, Bc>::value == false, "");static_assert(std::is_same<int, Cc>::value == false, "");static_assert(std::is_same<int, Dc>::value == true, "");// std::enable_if: 如果条件满足则启用类型// std::result_of: Obtains the result type of a call to Fn with arguments of the types listed in ArgTypesreturn 0;
}
以上代码主要参考:cplusplus cppreference
GitHub:https://github.com/fengbingchun/Messy_Test
相关文章:
反季大清仓,最低仅需34.9元
不知不觉已经12月份了还有一个月就要过年啦很多地方已经进入了寒冬的季节有的地方已经开启了下雪模式纷纷开始买冬天的商品棉衣、羽绒服、取暖器......但是.......今天我是来搞反季清仓的快来看看今天的反季清仓有啥商品~●反季清仓商品—程序员专属定制T ●专属定制T_shirt&am…

iOS 预览word pdf 文件
此类用于改变QLPreviewController 导航栏title #import <QuickLook/QuickLook.h> NS_ASSUME_NONNULL_BEGIN interface QLPreviewController (title) property (nonatomic, strong) NSString *qlpTitle; end NS_ASSUME_NONNULL_END #import "QLPreviewControllertitl…

Java过滤器模式
//创建一个类,在该类上应用标准 public class Person { private String name; private String gender; private String maritalStatus; public Person(String name, String gender, String maritalStatus) { this.name name; …

C++中指向类成员指针的用法
C中,指向类的成员指针包含两种: (1).指向类的成员函数的指针: 类型 (类名::* 函数成员指针名)(参数表); 函数成员指针名 &类名::函数成员名; 也可将以上两条语句调整为一条语句: 类型 (类名::* 函数成员指针名)(参数表) &…
多模态人物识别技术及其在爱奇艺视频场景中的应用 | 公开课笔记
【12月公开课预告】,入群直接获取报名地址12月11日晚8点直播主题:人工智能消化道病理辅助诊断平台——从方法到落地12月12日晚8点直播:利用容器技术打造AI公司技术中台12月17日晚8点直播主题:可重构计算:能效比、通用性…

JsonObject json字符串转换成JSonObject对象
字符串:{"code":"1004","msg":"请先添加系统靠勤人员信息!","userRegistInfo":{"acc":"小谷","id":0,"phoneMac":"","phoneNum":"…
基于人脸关键点修复人脸,腾讯等提出优于SOTA的LaFIn生成网络
作者 | Yang Yang、Xiaojie Guo、Jiayi Ma、Lin Ma、Haibin Ling译者 | 刘畅编辑 | Jane出品 | AI科技大本营(ID:rgznai100)【导语】现实场景中,人脸的变化是很大的,例如不同的姿势、表情和遮挡等,因此在现…

在Ubuntu上编译opencv 2.4.13源码支持android平台操作步骤
之前在https://blog.csdn.net/fengbingchun/article/details/96430706中编译过opencv源码用于海思平台,这里通过修改脚本编译opencv 2.4.13.6源码,使其支持android平台。 1. 从https://github.com/opencv/opencv/releases下载opencv 2.4.13.6源码&#…

Java组合模式
组合模式:适用于把一组相似的对象当作一个单一的对象,组合迷失一句树形结构来组合对象,用来表示部分以及整体层次。这种类的设计模式属于结构型模式,他创建了对象组的树形结构 这种模式创建了一个包含自己对象组的的类。给类提供了…

SQL故障转移集群操作方法
SQL故障转移集群操作方法1 给SQL服务器配置IP地址,每台服务器需要两个IP,一个通讯用,一个作为心跳线,修改计算机的名称,关闭服务器的防火墙,开启远程桌面.2心跳网卡配置去掉ipv6,并去掉下列几项进行验证3域控制器服务器管理器 添加角色 AD域服务启动AD域服务加入到域中打开DNS服…

Windows/Linux上使用fopen相关函数读取大文件
在介绍读取大文件之前,先了解下<cstdint>文件,标准头文件,存放固定宽度整数类型,如int32_t, uint32_t,不管在32位上还是64位上,长度都为4个字节;int64_t, uint64_t,不管在32位…
蚂蚁金服提新概率图模型GLN,正确率提升8.2%,具备可解释性 | NeurIPS 2019
作者 | 蚂蚁金服编辑 | Jane出品 | AI科技大本营(ID;rgznai100)【导读】一年一度的国际顶级学术会议NeurIPS 2019将于12月8日至14日在加拿大温哥华举行。作为人工智能和机器学习领域最顶级的盛会之一,每年都会吸引来自全世界的AI大…

Java外观模式
外观模式:隐藏系统的复杂性,并向客户提供了一个客户端可以访问系统的接口,这种类型的设计模式属于结构型模式,他向现有的系统添加一个接口,来隐藏系统的复杂性 这种模式设计到一个单一的类,该类提供了客户请…

【spring框架】spring整合hibernate初步
spring与hibernate做整合的时候,首先我们要获得sessionFactory。我们一般只需要操作一个sessionFactory,也就是一个"单例",这一点很适合交给spring来管理。下面的代码演示如何创建一个JDBC DataSource 和Hibernate SessionFactory:…

PyTorch简介
PyTorch是一个针对深度学习,并且使用GPU和CPU来优化的tensor library(张量库)。最新发布的稳定版本为1.9,源码在https://github.com/pytorch/pytorch 。它支持在Linux、Mac和Windows上编译和运行。调用Python接口可以通过Anaconda或Pip的方式安装&#x…

Java 责任链模式
顾名思义,责任链模式(Chain of Responsibility Pattern)为请求创建了一个接收者对象的链。这种模式给予请求的类型,对请求的发送者和接收者进行解耦。这种类型的设计模式属于行为型模式。 在这种模式中,通常每个接收者…
2019嵌入式智能国际大会圆满落幕,7大专场精彩瞬间释出!
全球第二大市场研究机构MarketsandMarkets报告称,2019年全球AIoT市场规模为51亿美元,到2024年,这一数字将增长至162亿美元。5G元年,人工智能开始更多地转向应用智能。基于此,12月6-7日,由哈尔滨工业大学&am…

ubuntu12.04 alternate win7 双系统安装
ubuntu alternate的安装比desktop复杂一点,因为alternate的安装过程有个步骤是检测cd-rom,如果你是刻盘安装,自然没问题,但是,现在的安装一般是将系统刻到U盘里,或者在硬盘中划出一个分区,将其制作成启动盘. 这里我是用U盘安装的... 安装前的准备: 1)在硬盘上分出一个空闲分区:…

C/C++包管理工具Conan简介
Conan是一个开源的、跨平台的、去中心化的C和C包管理器,它的源码在https://github.com/conan-io/conan ,License为MIT,最新发布版本为1.38.0,由Python实现。版本更新较频繁,但保持向前兼容。 Conan特点: (1…
神经架构搜索在视频理解中研究进展的综述
作者 | Michael S. Ryoo 研究员与 AJ Piergiovanni 学生研究员(Google 机器人团队)来源 | TensorFlow(ID:TensorFlow_official)视频理解一直是项颇具挑战性的难题。视频中包含时空数据,因此要提取特征表示需…

Java命令模式
命令模式(Command Pattern)是一种数据驱动的设计模式,它属于行为型模式。请求以命令的形式包裹在对象中,并传给调用对象。调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象,该对象执行命令…

关于本分类(codeforces-好题系列)
前前后后花了将近半个月,终于将吴神的十场cf的50题目补完了,看到了各种技巧和DP的好题,为了方便以后查阅,新增一个分类便于查找,当然本分类的题目其他分类一般都有,先去吃个饭,回来刷题解转载于…

Conan客户端简单使用示例
在https://blog.csdn.net/fengbingchun/article/details/118443862 中对Conan进行了简单介绍,这里调用openssl的接口,写一个简单的test来说明Conan的使用步骤: (1).首先添加一个conanfile.txt文件,内容如下:依赖项为op…

Java解释器模式
解释器模式(Interpreter Pattern)提供了评估语言的语法或表达式的方式,它属于行为型模式。这种模式实现了一个表达式接口,该接口解释一个特定的上下文。这种模式被用在 SQL 解析、符号处理引擎等。 意图:给定一个语言&…
为什么鲜有炫富的程序员?看看中国各阶级收入统计表
网上那些口口声声随随便便就能年入百万的,听听就行。作为开发者,可以不参加双11,但是花钱最多的地方就是买电子产品和“买课”。他们的炫富就是:你根本不知道有多贵的机械键盘,为了赚钱和幸福,又买了多少大…

HQL中的Like查询需要注意的地方
public List getOrgan(String organCode, String organName) { String hsql; List list; if (organCode ! null && organCode.length() > 0) { hsql "from Ab31 where bae002 ? and aab061 like ?"; list getHibernateTemplate().find…

深度神经网络中的Batch Normalization介绍及实现
之前在经典网络DenseNet介绍_fengbingchun的博客-CSDN博客_densenet中介绍DenseNet时,网络中会有BN层,即Batch Normalization,在每个Dense Block中都会有BN参与运算,下面对BN进行介绍并给出C和PyTorch实现。 Batch Normalization即…
韬光养晦的Sony AI,凭什么与Google和Facebook平起平坐?
作者 | 藏狐来源 | 脑极体(ID:unity007)伴随着感恩节气氛的日渐浓重,面对只剩下最后一个月份额的2019,奋进的、错失的,都已尘埃落定,是时候迎来盘点得失、清理思绪的冬藏时节了。整体来看&#…

Java迭代器模式
迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常用的设计模式。这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示。 迭代器模式属于行为型模式。 意图:提供一种方法顺序访问一个聚合对象中各个元…

Linux下搭建高效的SVN
第一种安装方式:svn下载:http://archive.apache.org/dist/subversion/需要的包yum install gcc gcc-cyum install expat-develyum install openssl-develhttp://labs.renren.com/apache-mirror//httpd/httpd-2.2.22.tar.gz //最好用2.2版本http://subver…