假设以下简单代码:
private const int A = 2;
private const int B = 3;
public int Result
{
get
{
return A * B;
}
}
Run Code Online (Sandbox Code Playgroud)
我很多次使用Result属性.
每次都会重新计算产品A*B吗?
我有一个不可变对象,例如笛卡尔空间中的一个节点.该类是不可变的,所以我缓存hashCode非常快速的散列.
private final int hashCode;
private final double x, y, z;
public Node(final double x, final double y, final double z)
{
this.x = x;
this.y = y;
this.z = z;
this.hashCode = Objects.hashCode(this.x, this.y, this.z);
}
@Override
public boolean equals(final Object obj)
{
if (this == obj) { return true; }
if (obj == null) { return false; }
if (!(obj instanceof Node)) { return false; }
final Node other = (Node) obj;
return Objects.equal(this.x, other.x) && …Run Code Online (Sandbox Code Playgroud) 我试图将Howard stack_allocHinnant 's 与boost rtrees 一起使用,如以下示例所示:
#include "stack_alloc.h"
#include <boost/geometry/index/rtree.hpp>
using NodePoint = boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>;
using Linear = boost::geometry::index::linear<8, 2>;
using RTree =
boost::geometry::index::rtree<NodePoint, Linear, boost::geometry::index::indexable<NodePoint>,
boost::geometry::index::equal_to<NodePoint>,
stack_alloc<NodePoint, 100>>;
int main()
{
RTree my_tree{};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
无法使用相当大的模板错误堆栈进行编译。我认为问题的核心是:
/usr/local/include/boost/geometry/index/detail/rtree/node/variant_static.hpp:26:7:错误:无效使用了不完整的类型'class boost :: geometry :: index :: detail :: rtree: :allocators,100>,boost :: geometry :: model :: point,boost :: geometry :: index :: linear <8,2>,boost :: geometry :: model :: box>,boost :: geometry: :index :: detail :: rtree :: node_variant_static_tag>'
这是带有完整错误的 …