首页 \ 问答 \ 使用std :: vector :: begin vs begin(vector)(Use std::vector::begin vs begin(vector))

使用std :: vector :: begin vs begin(vector)(Use std::vector::begin vs begin(vector))

如果我有std::vector (这是一个std::vector并且总是一个std::vector )。

是否优于使用std::begin()而不是std::vector::begin() (或相反)?

是否有任何性能增加/减少?

例:

std::vector<int> foo(100, 5);
std::sort(foo.begin(), foo.end());        // Case 1
std::sort(std:begin(foo), std::end(foo)); // Case 2

If I have std::vector (which is a std::vector and will be always a std::vector).

Is it superior to use std::begin() instead of std::vector::begin() (or the opposite)?

Will there be any performance increase/decrease?

Example:

std::vector<int> foo(100, 5);
std::sort(foo.begin(), foo.end());        // Case 1
std::sort(std:begin(foo), std::end(foo)); // Case 2

原文:https://stackoverflow.com/questions/35431537
更新时间:2023-08-29 16:08

最满意答案

可能的根本原因

我有同样的问题,并且发现它正在发生,因为我没有在我的应用程序窗口中设置根视图控制器。

在其中实现了preferredStatusBarStyleUIViewControllerUITabBarController ,它控制了屏幕上的视图的外观。

当我将根视图控制器设置为指向此UITabBarController ,状态栏更改开始正常工作,正如预期的那样(并且preferredStatusBarStyle方法被调用)。

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ... // other view controller loading/setup code

    self.window.rootViewController = rootTabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

替代方法(iOS 9中已弃用)

或者,您可以根据自己的背景颜色,在每个视图控制器中根据需要调用以下方法之一,而不必使用setNeedsStatusBarAppearanceUpdate

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

要么

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

请注意,如果您使用此方法,您还需要在plist文件中将UIViewControllerBasedStatusBarAppearance设置为NO


Possible root cause

I had the same problem, and figured out it was happening because I wasn't setting the root view controller in my application window.

The UIViewController in which I had implemented the preferredStatusBarStyle was used in a UITabBarController, which controlled the appearance of the views on the screen.

When I set the root view controller to point to this UITabBarController, the status bar changes started to work correctly, as expected (and the preferredStatusBarStyle method was getting called).

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ... // other view controller loading/setup code

    self.window.rootViewController = rootTabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

Alternative method (Deprecated in iOS 9)

Alternatively, you can call one of the following methods, as appropriate, in each of your view controllers, depending on its background color, instead of having to use setNeedsStatusBarAppearanceUpdate:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

or

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

Note that you'll also need to set UIViewControllerBasedStatusBarAppearance to NO in the plist file if you use this method.

相关问答

更多
  • 尝试在切换之前插入此行: NSLog(@"code: %ld", code); Try to insert this line just before the switch: NSLog(@"code: %ld", code);
  • 这在ActionBarSherlock中是不可避免的,我在检查github上的问题页面时忽略了这个问题。 基本上,嵌套片段中选项菜单的功能尚未添加,请参阅: https : //github.com/JakeWharton/ActionBarSherlock/issues/828 。 我现在的解决方案是用注释中的修改文件之一替换Watson.java。 It was, somewhat inevitably, an issue with ActionBarSherlock that I'd overlook ...
  • 最后,我使用了一种交叉点击方法,在适配器分配给每个视图的内部onClick()侦听器中调用我想要的onItemClickListener回调.... 有点像这样 public SomeAdapter(Context context, int textViewResourceId, List objects, OnItemClickListener clickListener) { super(context, textViewResourceId, objects) ...
  • 看起来你错过了一些东西 @Override protected void onPostExecute(Void result) { super.onPostExecute(result); if (exception.contains("java.net.UnknownHostException")) { MainActivity.showDialog(); Log.i("Error Message", "ERROR MESSAGE SHOWN"); ...
  • 可能的根本原因 我有同样的问题,并且发现它正在发生,因为我没有在我的应用程序窗口中设置根视图控制器。 在其中实现了preferredStatusBarStyle的UIViewController在UITabBarController ,它控制了屏幕上的视图的外观。 当我将根视图控制器设置为指向此UITabBarController ,状态栏更改开始正常工作,正如预期的那样(并且preferredStatusBarStyle方法被调用)。 (BOOL)application:(UIApplication *) ...
  • 从您的代码中删除extends TestCase 。 例如: import org.junit.After; import org.junit.Before; import org.junit.Test; public class CalcDateToolTest { DatesCalculator calc; @Before public void initialize() { System.out.println("Before"); calc ...
  • 我从Foxandxss得到了Angular频道对irc的回答,这就是他所说的。 有两种不同的注射位置服务,控制器,指令,运行哦和过滤器,你可以注入服务但不是提供者那么,你有另一个注入位置,提供者和配置功能,你只能注入常量和提供者所以提供者有两个如果你将提供者注入另一个提供者或配置你注入配置部分,你必须在名称上附加提供者,所以当你将“提供者部分,即配置”和“工厂”分成它时,它就是$ get注入“unicornLauncher”到配置你应该把“unicornLauncherProvider”注入配置部分,而不是 ...
  • 与您的代码一起,In Info.plist将基于视图控制器的状态栏外观视为NO Along with your code, In Info.plist put View controller-based status bar appearance as NO
  • 使用此代码获取confi chage override fun onConfigurationChanged(newConfig: Configuration?) { super.onConfigurationChanged(newConfig) if (newConfig != null) { if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { ...
  • 我想通了,基本上我没想到。 激活导体/根视图的构造函数中的视图无法正常工作,因为它尚未激活。 在调用指挥/根视图的OnActivate之前, IsActive不会设置为true。 这在某些时候可能是有问题的,因为即使调用OnInitialize时导体也不活动,并且这意味着一次初始化函数和OnActivate可以被多次调用。 在我的情况下它会很好,因为我的指挥是根视图所以OnActivate只会被调用一次。 故事的道德是,当导体是根视图时,不要在导体的构造函数中调用ActivateItem 。 I figur ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。