是否有一个等效的expr
命令适用于复数(代表两个双打的列表)?
该库提供了复数运算的函数,这似乎是定义所需cexpr
函数的有用实用程序,但它不能很好地工作.
例如,它没有正确处理括号.
ParseExpressions::ParseExpr { (1) + ((2) + (3)) } { }
Run Code Online (Sandbox Code Playgroud)
回报
+ [+ 1 ((2)] (3))
Run Code Online (Sandbox Code Playgroud)
虽然它应该回来
+ [+ 1 2] 3
Run Code Online (Sandbox Code Playgroud)
还有ParseExpressions :: ParseExpr {{1 2} + {3 4}} {}
回报
+ 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
虽然它应该回来
+ {1 2} {3 4}
Run Code Online (Sandbox Code Playgroud)
所以基本上我要求这个实用程序的强大版本.
diff
有一个选项-I regexp
,它忽略只插入或删除与给定正则表达式匹配的行的更改.我需要对这种情况进行类比,当两行之间发生变化时(而不是插入或删除行).
例如,我想忽略所有差异,例如,"abXd"
和"abYd"
给定X
和Y
.
似乎diff
没有这种能力.有没有合适的替代品diff
?
有没有办法在MATLAB类中定义静态成员变量?
这不起作用:
classdef A
properties ( Static )
m = 0;
end
end
Run Code Online (Sandbox Code Playgroud)
它建议使用关键字"常量"而不是"静态",不能修改常量属性.我想要一个对所有类对象通用的变量A
,我希望能够在类的方法中修改该变量A
.
所以我需要的是一个私有静态成员变量.有没有办法在MATLAB中获得它?
发现可以使用静态成员函数中的持久变量来完成变通方法.
在这种情况下,您应该从基类继承所有类,如下所示.
classdef object < handle
properties ( GetAccess = 'public', SetAccess = 'private' )
id
end
methods ( Access = 'protected' )
function obj = object()
obj.id = object.increment();
end
end
methods ( Static, Access = 'private' )
function result = increment()
persistent stamp;
if isempty( stamp )
stamp = 0;
end
stamp = stamp + uint32(1); …
Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
template < typename T >
struct A
{
struct B { };
};
template < typename T >
void f( typename A<T>::B ) { }
int main()
{
A<int>::B x;
f( x ); // fails for gcc-4.1.2
f<int>( x ); // passes
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以这里gcc-4.1.2要求f
明确指定模板参数.这符合标准吗?较新版本的GCC是否修复了此问题?如何避免int
在调用时明确指定f
?
更新: 这是一个解决方法.
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
template < typename T >
struct A
{
typedef T argument;
struct B { typedef A outer; };
};
template < …
Run Code Online (Sandbox Code Playgroud) 说有两个功能:
void ff( const std::tuple<const int&> ) { }
template < typename TT >
void gg( const std::tuple<const TT&> ) { }
Run Code Online (Sandbox Code Playgroud)
并调用这些函数:
int xx = 0;
ff( std::tie( xx ) ); // passes
gg( std::tie( xx ) ); // FAILS !!
Run Code Online (Sandbox Code Playgroud)
GCC 4.7.2无法编译最后一行并报告错误说明,如:
note: template argument deduction/substitution failed:
note: types ‘const TT’ and ‘int’ have incompatible cv-qualifiers
note: ‘std::tuple<int&>’ is not derived from ‘std::tuple<const TT&>’
Run Code Online (Sandbox Code Playgroud)
第一个问题是,如果这符合C++ 11标准,如果不符合,那么为什么呢?
此外,要克服这个问题,需要传递一个const引用元组,gg
而不是传递一个非const引用元组(这std::tie
使得).这可以通过以下方式完成:
gg( std::tie( std::cref(x) ) );
Run Code Online (Sandbox Code Playgroud)
然而,额外的调用std::cref …
在64位主机上,我试图用-m32
选项构建共享库.这些库是否可以与常规的64位库链接?
我正在做这样的事情:
g++ -m32 -shared source.cpp -l 64_bit_library.so -o 32_bit_library.so
Run Code Online (Sandbox Code Playgroud)
并收到如下错误消息:
/usr/bin/ld: skipping incompatible 64_bit_library.so
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何64_bit_library.so
以及32_bit_library.so
应该在64位主机上编译,以便32_bit_library.so
能够被链接64_bit_library.so
?
int plus unsigned int返回unsigned int.应该这样吗?
考虑以下代码:
#include <boost/static_assert.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/type_traits/is_same.hpp>
class test
{
static const int si = 0;
static const unsigned int ui = 0;
typedef BOOST_TYPEOF(si + ui) type;
BOOST_STATIC_ASSERT( ( boost::is_same<type, int>::value ) ); // fails
};
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud) 假设您有一个元组类型,并且您想要提取其模板参数包以便实例化另一个模板.如果那是一个类型模板,那么我可以有这样的实用程序:
template < typename Tuple, template <typename...> typename What >
struct PutTupleInT;
template < typename... Types, template <typename...> typename What >
struct PutTupleInT<std::tuple<Types...>, What>
{
using Result = What<Types...>;
};
Run Code Online (Sandbox Code Playgroud)
但是,如果所需模板是可变模板呢?虽然template <typename...> typename What
是类型模板的"占位符",但是变量模板的"占位符"是什么?
我已经尝试了以下forng-4.0.0(现在唯一支持自动类型的非类型模板参数的编译器),但它失败了.实际上我不确定这是否是C++ 17的正确语法.
template < typename Tuple, template <typename...> auto What >
struct PutTupleInV;
template < typename... Types, template <typename...> auto What >
struct PutTupleInV<std::tuple<Types...>, What>
{
static constexpr auto value = What<Types...>;
};
Run Code Online (Sandbox Code Playgroud) 应该不是的std ::调用是constexpr
特别是在C++中17 constexpr lambda表达式?
是否有任何阻碍这种情况的障碍?