我是任何类型的DB的新手.看起来你可以用图表形式表示任何关系数据库(虽然它可能是一个非常扁平的图形),以及关系数据库中的任何图形数据库(有足够的表).
通过从一个条目到另一个条目的硬链接,图形可以避免在其他表中进行大量查找,因此在很多/大多数情况下,我可以看到图形的速度优势.如果您的数据是自然分层的,特别是如果它形成一棵树,我会看到关系图上的逻辑/推理优势.我想象一个链接到其他节点的图形节点可能包含多个地图或列表......它实际上包含图形节点内的关系数据库.
图表db与关系数据库有什么不利之处吗?(注意:我不是在寻找实现中缺少功能的东西,而是理论上的优点/缺点)
我什么时候还应该使用关系数据库?即使我逻辑上有一个int到int的单一映射,我也可以在图中完成.
database graph non-relational-database relational-database nosql
我可以在cpp中定义一个专门的函数,就像这样......
//标题
template<typename T>
void func(T){}
template<>
void func<int>(int);
Run Code Online (Sandbox Code Playgroud)
// cpp
template<>
void func<int>(int)
{}
Run Code Online (Sandbox Code Playgroud)
如何在cpp中的专用类中定义方法?像这样(这不起作用,我得到error C2910: 'A<int>::func' : cannot be explicitly specialized)......
//标题
template<typename T>
struct A
{
static void func(T){}
};
template<>
struct A<int>
{
static void func(int);
};
Run Code Online (Sandbox Code Playgroud)
// cpp
template<>
void A<int>::func(int)
{}
Run Code Online (Sandbox Code Playgroud) template<typename T>
struct A
{
A<T> operator%( const T& x);
};
template<typename T>
A<T> A<T>::operator%( const T& x ) { ... }
Run Code Online (Sandbox Code Playgroud)
如何使用enable_if为任何浮点类型(is_floating_point)进行以下特化?
template<>
A<float> A<float>::operator%( const float& x ) { ... }
Run Code Online (Sandbox Code Playgroud)
编辑:这是我提出的答案,与下面发布的答案不同......
template<typename T>
struct A
{
T x;
A( const T& _x ) : x(_x) {}
template<typename Q>
typename std::enable_if<std::is_same<Q, T>::value && std::is_floating_point<Q>::value, A<T> >::type operator% ( const Q& right ) const
{
return A<T>(fmod(x, right));
}
template<typename Q>
typename std::enable_if<std::is_convertible<Q, T>::value && !std::is_floating_point<Q>::value, A<T> >::type operator% …Run Code Online (Sandbox Code Playgroud) int func(int x){return x;}
...
std::function<int(int)> x = std::bind(func, std::placeholders::_1);
x(123);
Run Code Online (Sandbox Code Playgroud)
x(123)实际上是否调用了生成operator()的仿函数,std::function而仿函数又调用了生成的最终调用operator()的仿函数?这是否被优化为最佳调用?std::bindfuncfunc(123)std::bind生成?在什么范围?怎么std::bind命名呢?(可以有名称冲突)std::bind吗?std::bind取而代之的是将它作为lambda实现的最佳选择?std::function?如何解析它以及如何在其他地方使用该模板参数语法?为什么允许这样做:
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
template<typename T>
struct invisible
{
static typename T::type value;
};
template<typename T>
typename T::type invisible<T>::value;
//////////////////////////////////////////////////////////////////////////
template<typename T, typename T::type P>
class construct_invisible
{
construct_invisible(){ invisible<T>::value = P; }
static const construct_invisible instance;
};
template<typename T, typename T::type P>
const construct_invisible<T, P> construct_invisible<T, P>::instance;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class A
{
public:
A(int x) : m_X(x){}
private:
int m_X;
};
//////////////////////////////////////////////////////////////////////////
struct A_x{ typedef int A::*type; };
template class construct_invisible<A_x, &A::m_X>;// <---- WHY DOES `&A::m_X` WORK HERE?
//////////////////////////////////////////////////////////////////////////
int …Run Code Online (Sandbox Code Playgroud) 我正在考虑使用typeid来解析类型的类型擦除设置......
struct BaseThing
{
virtual ~BaseThing() = 0 {}
};
template<typename T>
struct Thing : public BaseThing
{
T x;
};
struct A{};
struct B{};
int main()
{
BaseThing* pThing = new Thing<B>();
const std::type_info& x = typeid(*pThing);
if( x == typeid(Thing<B>))
{
std::cout << "pThing is a Thing<B>!\n";
Thing<B>* pB = static_cast<Thing<B>*>(pThing);
}
else if( x == typeid(Thing<A>))
{
std::cout << "pThing is a Thing<A>!\n";
Thing<A>* pA = static_cast<Thing<A>*>(pThing);
}
}
Run Code Online (Sandbox Code Playgroud)
我从未见过其他人这样做过.替代方案是BaseThing具有纯虚拟GetID(),用于推断类型而不是使用typeid.在这种情况下,只有1级继承,typeid的成本与虚函数调用的成本是多少?我知道typeid以某种方式使用vtable,但它究竟是如何工作的呢?
这是可取的而不是GetID(),因为尝试确保ID是唯一且确定的,需要相当多的hackery .
由于VideoToolbox不适用于tvOS,我该如何解码视频?
我有一个应用程序,我在内存中有h.264的帧(通过网络流),我之前使用VideoToolbox处理解码.什么是替代品?
如果我move shared_ptr'进shared_ptr''b'是'a'保证为空?
指定移动后是否为任何标准类的状态?
除非我错了,否则它们似乎都运行得很好 - 是否有一个最佳实践理由更喜欢一个而不是另一个?
例:
struct A
{
A(){}
A(const A&){ std::cout << "A(const A&)\n"; }
A(A&&){ std::cout << "A(A&&)\n"; }
};
struct B
{
B(){}
B(const B& right) : x(right.x){ std::cout << "B(const B&)\n"; }
B(B&& right) : x(std::forward<A>(right.x)){ std::cout << "B(B&&)\n"; }
A x;
};
struct C
{
C(){}
C(const C& right) : x(right.x){ std::cout << "C(const C&)\n"; }
C(C&& right) : x(std::move(right.x)){ std::cout << "C(C&&)\n"; }
A x;
};
struct D
{
D(){}
D(const D& right) : x(right.x){ …Run Code Online (Sandbox Code Playgroud) 我需要在编译时找出可以表示特定数字的最小无符号整数类型.像这样......
//////////////////////////////////////////////////////////////////////////
template<size_t Bits>
struct uint_least{};
template<>
struct uint_least<8>{ typedef std::uint8_t type; };
template<>
struct uint_least<16>{ typedef std::uint16_t type; };
//////////////////////////////////////////////////////////////////////////
template<size_t max>
struct uint_least_bits
{
static const size_t value = 14; // just a placeholder
};
//////////////////////////////////////////////////////////////////////////
template<size_t max>
class A
{
typedef typename uint_least<uint_least_bits<max>::value>::type underlying_type;
underlying_type m_X;
};
Run Code Online (Sandbox Code Playgroud)
uint_least是为了给你最小的无符号整数类型,它至少是Bits大的,它应该适用于任何高达64的值(不仅仅是8,16,32,64,还有1,4,13等).
uint_least_bits旨在为您提供表示所需的最小位数max.
uint_least?uint_least_bits?bits,min以及max是什么?如果答案是模板类型,我该如何防范无效输入?特征的确切结构无关紧要.随意废弃我提供的东西.我只需要提供一个数字并找回可以容纳它的最小无符号整数类型.
c++ ×8
c++11 ×6
templates ×3
boost ×1
database ×1
decoding ×1
graph ×1
nosql ×1
private ×1
shared-ptr ×1
tr1 ×1
tvos ×1
type-erasure ×1
type-traits ×1