问题列表 - 第33464页

找到后stl容器端是多余的,那么快捷方式是什么

让我们假设我们有一个地图类(无序地图,列表,集合,也可以做任何事情).我们正在寻找一个特定的元素.在调用find()成员之后,我们必须检查end()成员.但是find()在内部已经知道它是返回一个好的迭代器还是结束迭代器.我们为什么还需要再次调用end()?这增加了一些开销.

std::map<int,float> myMap;
// some other code to populate the map
// ...
std::map<int,float>::iterator myIt;
myIt = myMap.find(2); // doesn't this already know wheter its returning the end() iterator?
if (myIt != myMap.end()) { //calling end() here wastes some time because find
                           //already knew the result
   std::cout << "Found, value is "<<(*myIt).second<<"\n";
} else {
   std::cout << "Not found.\n";
}
Run Code Online (Sandbox Code Playgroud)

应该有一种方法可以在不调用end()的情况下知道find()的结果.

c++ stl

-1
推荐指数
1
解决办法
227
查看次数

pushViewController是否保留了控制器?

我很难找出pushViewController是否保留了控制器,目前我有以下代码(有效)...

ColorController *colorController = [[ColorController alloc] initWithNibName:nibColor bundle:nil];
[[self navigationController] pushViewController:colorController animated:YES];
[colorController release];
Run Code Online (Sandbox Code Playgroud)

但我正在考虑删除发布并添加自动释放...

ColorController *colorController = [[[ColorController alloc] initWithNibName:nibColor bundle:nil] autorelease];
[[self navigationController] pushViewController:colorController animated:YES];
Run Code Online (Sandbox Code Playgroud)

非常感激

加里

iphone cocoa-touch objective-c

11
推荐指数
1
解决办法
2731
查看次数

Integer和NSDecimalNumber的基本数学问题 - 二进制的操作数无效

男人最简单的东西在Objective-C中对我来说似乎总是那么疯狂,无论如何我需要做一些基本的减法和乘法而且难倒.

我有:

client.PricingDiscount <-- this is an Integer 16 property on a CoreData NSManagedObject
sku.RetailPrice <-- this is a Decimal property on a CoreData NSManagedObject
Run Code Online (Sandbox Code Playgroud)

我只是想让NSDecimalNumber像这样显示:

NSDecimalNumber *showPrice = sku.RetailPrice * (100 - client.PricingDiscount);
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一些不同形式的这个,无法弄清楚我到底做错了什么.

iphone objective-c

7
推荐指数
1
解决办法
5578
查看次数

确定哪些可执行文件链接到 Linux 上的特定共享库

如何列出 Red Hat Linux 系统上链接到 libssl 的所有可执行文件?我可以接近:

find / -type f -perm /a+x -exec ldd {} \; | grep libssl   
Run Code Online (Sandbox Code Playgroud)

ldd 显示了可执行文件链接到的库,但是包含库名称的行并不显示文件名,因此虽然我使用 grep 得到了很多匹配项,但我不知道如何返回该库的名称发生匹配的可执行文件。任何帮助将不胜感激。

linux shared-libraries ldd

3
推荐指数
1
解决办法
1905
查看次数

如何在UNix上使用pow()和sqrt()?

如何在Ubuntu中使用pow()和sqrt()函数?我已经包含math.h头文件,但它仍然给我一个错误.

c

5
推荐指数
2
解决办法
3477
查看次数

在NSSearchField中显示进度指示器

我正在使用NSSearchField通过Internet运行查询并在表格视图中显示结果.在查询运行时,我想在NSSearchField中显示进度指示器?我想我以前在另一个应用程序中看到过这个.

是否有可用于实现此目的的开源组件?

我该怎么做呢?什么是最好的方法?有什么陷阱?

macos cocoa objective-c nssearchfield

5
推荐指数
1
解决办法
613
查看次数

使用 NSImage 操作制作裁剪效果

我有一个显示图像的 NSView,我想让这个视图像裁剪图像效果一样。然后,我让3个矩形(imageRectsecRectIntersectRect)时,imageRect是显示图像的矩形,secRect是矩形这只是充当变暗整体imageRect,并且intersectRect是像一个观察的rect一个矩形,我想要做的是什么样的做一个“洞” 就secRect直接看到了imageRect(没有变暗)。这是我的 drawRect 方法:

- (void)drawRect:(NSRect)rect {
    // Drawing code here.
 NSImage *image = [NSImage imageNamed:@"Lonely_Tree_by_sican.jpg"];
 NSRect imageRect = [self bounds];

 [image compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver ];

 if (NSIntersectsRect([myDrawRect currentRect], [self bounds])) {
  //get the intersectionRect
  intersectionRect = NSIntersectionRect([myDrawRect currentRect], imageRect);

  //draw the imageRect
  [image compositeToPoint:imageRect.origin operation:NSCompositeSourceOver];

  //draw the secRect and fill it with black and alpha 0.5
  NSRect secRect = NSMakeRect(imageRect.origin.x, imageRect.origin.y, …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nsimage

1
推荐指数
1
解决办法
3794
查看次数

在SQL Server中生成递增数字的函数

有没有办法从函数中选择并让它返回递增的数字?

例如,执行以下操作:

SELECT SomeColumn, IncrementingNumbersFunction() FROM SomeTable
Run Code Online (Sandbox Code Playgroud)

让它回归:

SomeColumn | IncrementingNumbers
--------------------------------
some text  | 0
something  | 1
foo        | 2
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server

2
推荐指数
1
解决办法
1万
查看次数

按任意时间间隔对DateTime进行分组

我有一个IEnumerable的项类定义如下:

public class Item {
    public DateTime Date { get; private set; }
    public decimal? Value { get; private set; }

    public Item(DateTime date, decimal? value) {
     Date = date;
     Value = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

这些项目处于特定的时间间隔(例如5分钟).我需要按日期对它们进行分组,但需要更改间隔.例如,如果项目按以下顺序排列:

2010-08-24 00:05
2010-08-24 00:10
2010-08-24 00:15
2010-08-24 00:20
2010-08-24 00:25
2010-08-24 00:30
Run Code Online (Sandbox Code Playgroud)

我希望将它们分成15分钟的间隔,结果应如下所示:

2010-08-24 00:15
2010-08-24 00:30
Run Code Online (Sandbox Code Playgroud)

间隔由另一个类提供,但我可以得到表示该间隔的毫秒数(例如,Interval.FromMinutes(5).GetMilliseconds()应该返回300000).问题是如何编写一个分组函数,允许我做这样的事情:data = items.GroupBy(t => GroupingFunction(t.DateTime, interval))并获得结果?

更新:间隔不一定以分钟为单位.它可能是几小时,几分钟甚至几天.

c# linq group-by

7
推荐指数
1
解决办法
5346
查看次数

是否有regsvr32的.NET或Win32版本?

是否有regsvr32的.NET或Win32版本?我想用代码注册一个COM DLL而不是shells到regsvr32程序.

.net installation regsvr32

1
推荐指数
1
解决办法
515
查看次数