std::is_constructible具有私有或受保护的析构函数的类型的预期结果是什么?
例如,我仍然可以在堆上构造这样的对象,即使只有朋友可以释放它:
#include <type_traits>
class Foo
{
friend void freeFoo(Foo*);
public:
Foo()
{}
private:
// Destructor is private!
~Foo()
{}
};
void freeFoo(Foo* f)
{
delete f; // deleting a foo is fine here because of friendship
}
int main()
{
Foo* f = new Foo();
// delete f; // won't compile: ~Foo is private
freeFoo(f); // fine because of friendship
if(!std::is_constructible<Foo>::value)
{
std::cout << "is_constructible failed" << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
is_constructible对gcc和Visual C++(coliru上的gcc演示)进行最终检查都会失败.
这是标准所要求的行为吗?如果是这样,有没有办法检查类型是否具有特定的构造函数,无论析构函数上的访问说明符是什么?
如何配置 CMake 以将编译器警告视为构建期间的错误?
我知道可以-Werror通过诸如 之类的命令手动配置编译器的命令行选项target_compile_options,但我更喜欢不需要摆弄依赖于工具的选项的便携式解决方案。
这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(/usr/include/gtest)
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests gtest.cpp)
target_link_libraries(runTests /usr/lib/gtest pthread)
Run Code Online (Sandbox Code Playgroud)
运行cmake时出现以下错误:
michael@michaelFriko:~/workspace/gtest/src$ cmake CMakeLists.txt
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindGTest.cmake:150 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:8 (find_package)
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?
我确信如果你绑定一个缓冲区glBindBuffer(),你可以安全地假设它保持绑定,直到目标通过另一个调用反弹glBindBuffer().因此,当我发现调用glBindVertexArray()将绑定到GL_ELEMENT_ARRAY目标的缓冲区设置为0 时,我感到非常惊讶.
这是最小的C++示例代码:
GLuint buff;
glGenBuffers(1, &buff);
std::cout << "Buffer is " << buff << "\n";
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buff);
GLuint vao;
glGenVertexArrays(1, &vao);
GLint bound_buff;
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &bound_buff);
std::cout << "Bound before glBindVertexArray: " << bound_buff << "\n";
glBindVertexArray(vao);
// ^- an implicit glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); ?
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &bound_buff);
std::cout << "Bound after glBindVertexArray: " << bound_buff << "\n";
Run Code Online (Sandbox Code Playgroud)
我在初始化OpenGL 3.2设备上下文后立即运行此代码并获得以下输出:
Buffer is 1
Bound before glBindVertexArray: 1
Bound after glBindVertexArray: 0
Run Code Online (Sandbox Code Playgroud)
另一方面,GL_ARRAY_BUFFER 不会被呼叫改变.我检查了OpenGL 3.2规范(2.10),glBindVertexArray没有发现这种意想不到的副作用. …
Alice和Bob玩下面的游戏:
1)他们选择开头的前N个数字的排列.
2)他们交替上场,爱丽丝先上场.
3)在一个回合中,他们可以从排列中删除任何一个剩余的数字.
4)当剩余数字形成递增序列时,游戏结束.最后一个回合(在序列变得增加之后)的人赢得比赛.
假设两者都发挥得最好,谁赢了比赛?
输入:第一行包含测试用例数T.T测试用例如下.每个案例在第一行包含一个整数N,然后在第二行包含整数1..N的排列.
输出:输出T行,每个测试用例一行,如果Alice赢了游戏则包含"Alice",否则包含"Bob".
样本输入:
2
3
1 3 2
五
5 3 2 1 4
样本输出:
爱丽丝
短发
约束:
1 <= T <= 100
2 <= N <= 15
排列最初不会是增加的顺序.
我想解决上面的问题.我已经衍生到很远,但我陷入了困境.请帮我继续.
在上述问题中,对于长度为2的排列,玩家1总是获胜.
对于长度为3的置换,如果字符串严格增加或减少,则播放器2获胜.
对于长度为4的排列,如果玩家1能够通过移除角色使弦完全增加或减少,则她赢得其他玩家2胜.
因此得出的结论是:
如果当前玩家能够使字符串严格增加他/她获胜.(琐碎案例)
如果他/她能够使其严格减少,则获胜者由该序列中的元素数量决定.如果该序列中有偶数个元素,则当前玩家会失败,否则获胜.
但是,如果结果字符串既不增加也不减少,应该怎么办?
当我使用此查询时:
SELECT TOP 20
f.name as f_firm_name
FROM Firm f
WHERE f.id_city = '73041' COLLATE SQL_Latin1_General_Cp1251_CI_AS
ORDER BY f.name ASC
Run Code Online (Sandbox Code Playgroud)
我得到这些结果:
f_firm_name
--------------------------------
SKY LINE STUDIO
??????????? ?????
????? ?????????
??????? ???
???????????+
???????????????????
?? ??????
??????? ?.?.??
??????
?? ??????? ?.?.
?? ???????? ??????
(20 row(s) affected)
Run Code Online (Sandbox Code Playgroud)
但是如果我使用这个查询:
SELECT TOP 20
f.name as f_firm_name
FROM Firm f
WHERE f.id_city='73041'
AND f.name LIKE '??????? ???%' COLLATE SQL_Latin1_General_Cp1251_CI_AS
ORDER BY f.name ASC
Run Code Online (Sandbox Code Playgroud)
我得到这些结果:
f_firm_name
-----------------
(0 row(s) affected)
Run Code Online (Sandbox Code Playgroud)
为什么我0 rows …
我可以说,我的计算机上有一个程序 C:/Tools/generate_v23_debug.exe
我有一个FindGenerate.cmake文件,它允许CMake找到可执行文件的确切路径.
所以在我的CMake代码中,我这样做:
find_program(Generate)
if (NOT Generate_FOUND)
message(FATAL_ERROR "Generator not found!")
Run Code Online (Sandbox Code Playgroud)
所以CMake找到了可执行文件.现在我想在自定义命令语句中调用此程序.我应该使用COMMAND Generator或COMMAND ${GENERATOR_EXECUTABLE}?这两个都会做同样的事情吗?一个比另一个更受欢迎吗?name_EXECUTABLE是CMake将定义的变量(它不在FindGenerate.cmake文件中),还是特定于我正在查看的其他人的示例代码?会COMMAND Generator扩展到正确的道路吗?
add_custom_command(
OUTPUT blahblah.txt
COMMAND Generator inputfile1.log
DEPENDS Generator
)
Run Code Online (Sandbox Code Playgroud) 我试图在 Fedora 22 上编译一个软件(SuperCollider),但我遇到了一个问题:
libsupernova.a(server.cpp.o): In function `std::atomic<boost::lockfree::detail::tagged_index>::is_lock_free() const':
/usr/include/c++/5.1.1/atomic:212: undefined reference to `__atomic_is_lock_free'
collect2: error: ld returned 1 exit status
server/supernova/CMakeFiles/supernova.dir/build.make:96: recipe for target 'server/supernova/supernova' failed
make[2]: *** [server/supernova/supernova] Error 1
CMakeFiles/Makefile2:3383: recipe for target 'server/supernova/CMakeFiles/supernova.dir/all' failed
make[1]: *** [server/supernova/CMakeFiles/supernova.dir/all] Error 2
Makefile:146: recipe for target 'all' failed
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)
在我看来,这是 libatomic 的一个问题。gcc 是否可能没有链接到 libatomic?
有人对如何解决这个问题有任何想法吗?
另一个想法是尝试安装-latomic,但我找不到有关的信息。相反,我已经安装了 libatomic。我不知道它们是否相同。
C++20 introduces proper Concepts for the different types of iterators in the standard library (input, output, forward, bidirectional, random access, ...).
While the original named requirements for those types did not mention the iterator tags from std::iterator_traits at all, the new C++20 concepts explicitly require them. See for example the input_iterator Concept ([iterator.concept.input]):
template<class I>
concept input_iterator =
input_or_output_iterator<I> &&
indirectly_readable<I> &&
requires { typename ITER_CONCEPT(I); } &&
derived_from<ITER_CONCEPT(I), input_iterator_tag>;
Run Code Online (Sandbox Code Playgroud)
Notice the check for the iterator tag in …
我的应用程序有单独的算法来获取滚动更改和用户位置更改的数据.对于位置更改使用com.google.android.gms.location.LocationListener 哪个工作正常.
但对于用户滚动,我得到了 mMap.setOnCameraChangeListener(new OnCameraChangeListener().但问题是com.google.android.gms.location.LocationListene还会触发 mMap.setOnCameraChangeListener(new OnCameraChangeListener().
那么如何区分.目前我使用布尔值来区分,但它不可靠和肮脏.
c++ ×5
cmake ×3
algorithm ×1
android ×1
boost ×1
c++-concepts ×1
c++11 ×1
c++20 ×1
events ×1
fedora ×1
game-theory ×1
gcc ×1
math ×1
nvidia ×1
opengl ×1
opengl-3 ×1
scroll ×1
sql-server ×1
type-traits ×1