此代码被(至少)MSVC,ICC和GCC拒绝:
class A {
public:
A( int ) { }
};
class B: virtual public A {
public:
//B(): A( -1 ) { } // uncomment to make it compilable
virtual void do_something() = 0;
};
class C: public B {
public:
C(): A( 1 ) { }
virtual void do_something() { }
};
int main() {
C c;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在...的基础上
error : no default constructor exists for class "A"
class B: virtual public A {
^
detected …Run Code Online (Sandbox Code Playgroud) 标准说:"thread :: id类型的对象为所有不代表执行线程的线程对象提供了一个不同的值".这是单个/不同的值operator==,或者它是实际的按位单/不同值?
问题的原因:MSVC2012 std::thread::id::id()在其中一个字段中留下了垃圾,并且它打破了对比较交换的代码std::atomic<std::thread::id>(因为后者依赖于按位比较).
首先是std::atomic<std::thread::id>法律结构吗?
编辑:作为参考,代码如下:
while( !worker_id.compare_exchange_weak( no_id = thread_id_type(), self_id ) )
sleep();
Run Code Online (Sandbox Code Playgroud) 考虑到创建/加入线程时隐含的同步,该代码工作所需的最小框架是什么??没有?xstd::atomicvolatile
#include <thread>
#include <cassert>
int main() {
int x = 123; // ***
std::thread( [ & ] { assert( x == 123 ); x = 321; } ).join();
assert( x == 321 );
return 0;
}
Run Code Online (Sandbox Code Playgroud) 标准的promise/ packaged_task采用分配器的构造函数是应该仅将状态对象本身用于分配器,还是应该保证所有(内部)相关对象?
[futures.promise]:"...为共享状态分配内存"
[futures.task.members]:"...分配存储内部数据结构所需的内存"
特别是以下的错误或功能?
*Howard Hinnant的 MSVC 2013.4,Boost 1.57,short_alloc.h
例1
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include "short_alloc.h"
#include <cstdio>
void *operator new( std::size_t s ) {
printf( "alloc %Iu\n", s );
return malloc( s );
}
void operator delete( void *p ) {
free( p );
}
int main() {
const int N = 1024;
arena< N > a;
short_alloc< int, N > al( a );
printf( "[promise]\n" );
auto p = …Run Code Online (Sandbox Code Playgroud) 海湾合作委员会(5.3)和Clang(3.8)声称第一行test是坏的,但第二行是好的.MSVC(2015.2)说,两者都是无效的.
template< typename N, typename T >
void f( N n, T t ) { std::get< n >( t ); }
void test() {
std::get< std::integral_constant< size_t, 0 >() >( std::make_tuple( 123 ) ); // not ok
f( std::integral_constant< size_t, 0 >(), std::make_tuple( 123 ) ); // ok for gcc, clang, but not msvc
}
Run Code Online (Sandbox Code Playgroud)
根据标准,究竟是什么区别?此代码合法开头吗?
第一行的clang错误:
In file included from main.cpp:2:
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/tuple:874:34: error: no matching function for call to '__get_helper2'
{ return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:10:10: note: …Run Code Online (Sandbox Code Playgroud) 我一直enable_if以这种近似的方式使用各种版本的 GCC(最高 5.2):
template< bool b, std::enable_if_t< b >... >
void fn() { std::cout << 1 << std::endl; }
template< bool b, std::enable_if_t< !b >... >
void fn() { std::cout << 2 << std::endl; }
// ...
fn< true >();
fn< false >();
Run Code Online (Sandbox Code Playgroud)
但是,事实证明,Clang 3.7 不接受这一点(“调用‘fn’是不明确的”)。
Q1. 谁是对的,为什么?
当然,还有其他方法可以做到这一点,但我有点不喜欢
template< bool b >
std::enable_if_t< b, void > fa() { std::cout << 1 << std::endl; }
// ...
Run Code Online (Sandbox Code Playgroud)
以及它的同类,使函数签名的正常部分变得不那么可读,并且
template< bool b, std::enable_if_t< b, int > = 0 > …Run Code Online (Sandbox Code Playgroud) 因此,Racket(6.5)文档说您可以同时绑定多个ID:
(for ([(i j) #hash(("a" . 1) ("b" . 20))])
(display (list i j)))
Run Code Online (Sandbox Code Playgroud)
Bu-u-ut我无法找出/找到如何使用手动构造的数据执行此操作的示例:
(define a '(1 2 3 4 5))
(define b '(10 20 30 40 50))
(for ([(i j) (map list a b)])
(display (list i j)))
Run Code Online (Sandbox Code Playgroud)
与...爆炸
result arity mismatch;
expected number of values not received
expected: 2
received: 1
from:
in: local-binding form
values...:
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
在玩基于text-icu的解析时BreakIterator,我一直坚持实现这样的功能
conditionalParser :: (a -> Bool) -> Parser a -> Parser a -> Parser a -> Parser a
conditionalParser f a b c = do
a' <- a
if f a'
then b
else c
Run Code Online (Sandbox Code Playgroud)
但有一种类型
conditionalParserIO :: (a -> Bool) -> Parser (IO a) -> Parser (IO a) -> Parser (IO a) -> Parser (IO a)
Run Code Online (Sandbox Code Playgroud)
没有做可能unsafePerformIO吗?
到目前为止,我只能得到一些do具有最终返回类型的嵌套s Parser (IO (Parser (IO a))),但不知道如何折叠它们.