auto

Kafka单线程Consumer及参数详解

随声附和 提交于 2019-11-27 12:13:22
请使用0.9以后的版本: 示例代码 Properties props = new Properties(); props.put("bootstrap.servers", "kafka01:9092,kafka02:9092"); props.put("group.id", "test"); props.put("enable.auto.commit", "true"); props.put("auto.commit.interval.ms", "1000"); props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); props.put("auto.offset.reset","earliest"); KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); consumer.subscribe(Arrays.asList("foo", "bar")); try{ while (true) {

C++11 - declaring non-static data members as 'auto'

扶醉桌前 提交于 2019-11-27 12:01:17
Does C++11 allow declaring non-static data members as 'auto' if they are initialized in the declaration? For example: struct S { auto x = 5; // in place of 'int x = 5;', which is definitely allowed }; GCC 4.7 rejects the above code, while it accepts int x = 5; . Assuming this is not a compiler bug but rather the standard really doesn't allow it, why not? It would be just as useful as declaring local variables auto . The rule for prohibiting non-static members is in 7.1.6.4 clause 4: The auto type-specifier can also be used in declaring a variable in the condition of a selection statement (6.4)

Using auto in a lambda function

孤街浪徒 提交于 2019-11-27 11:55:32
问题 #include <vector> #include <algorithm> void foo( int ) { } int main() { std::vector< int > v( { 1,2,3 } ); std::for_each( v.begin(), v.end(), []( auto it ) { foo( it+5 ); } ); } When compiled, the example above starts the error output like this : h4.cpp: In function 'int main()': h4.cpp:13:47: error: parameter declared 'auto' h4.cpp: In lambda function: h4.cpp:13:59: error: 'it' was not declared in this scope Does it mean that the keyword auto should not be used in lambda expressions? This

How to declare array with auto

99封情书 提交于 2019-11-27 11:19:25
问题 I have been playing with auto and I noticed that for most cases you can replace a variable definition with auto and then assign the type. In the following code w and x are equivalent (default initialized int , but lets not get into potential copies). Is there a way to declare z such that it has the same type as y ? int w{}; auto x = int{}; int y[5]; auto z = int[5]; 回答1: TL;DR template<typename T, int N> using raw_array = T[N]; auto &&z = raw_array<int,5>{}; Your example of auto z = int[5];

How do I get a const_iterator using auto?

穿精又带淫゛_ 提交于 2019-11-27 10:41:45
问题 First question: is it possible to "force" a const_iterator using auto? For example: map<int> usa; //...init usa auto city_it = usa.find("New York"); I just want to query, instead of changing anything pointed by city_it , so I'd like to have city_it to be map<int>::const_iterator . But by using auto, city_it is the same to the return type of map::find() , which is map<int>::iterator . Any suggestion? 回答1: Sorry, but I just think the best suggestion is not using auto at all, since you want to

The new keyword “auto”; When should it be used to declare a variable type? [duplicate]

徘徊边缘 提交于 2019-11-27 10:14:27
Possible Duplicate: How much is too much with C++0x auto keyword Have we (as a community) had enough experience to determine when and/or whether auto is being abused? What I am really looking for is a best practices guide on when to use auto when it should be avoided Simple rules of thumb that can quickly be followed in 80% of cases. As a context this question is sparked by my response here I think when the type is very well-known amongst the co-programmers who work (or would work) in your project, then auto can be used, such as in the following code: //good : auto increases readability here

Why doesn't the C++11 'auto' keyword work for static members?

爱⌒轻易说出口 提交于 2019-11-27 08:42:44
class Foo { public: static const char *constant_string; }; auto Foo::constant_string = "foo"; int main(void) { }; Compiled with: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 like this: gcc -std=c++0x ./foo.cc ./foo.cc:6:11: error: conflicting declaration ‘auto Foo::constant_string’ ./foo.cc:3:22: error: ‘Foo::constant_string’ has a previous declaration as ‘const char* Foo::constant_string’ ./foo.cc:6:11: error: declaration of ‘const char* Foo::constant_string’ outside of class is not definition [-fpermissive] Is this intended behavior of the auto keyword, or a bug in gcc+ Lightness Races in Orbit

Does 'auto' type assignments of a pointer in c++11 require '*'?

不问归期 提交于 2019-11-27 06:48:33
Given my variable being a pointer, if I assign it to a variable of "auto" type, do I specify the "*" ? std::vector<MyClass> *getVector(); //returns populated vector //... std::vector<MyClass> *myvector = getVector(); //assume has n items in it auto newvar1 = myvector; // vs: auto *newvar2 = myvector; //goal is to behave like this assignment: std::vector<MyClass> *newvar3 = getVector(); I'm a bit confused on how this auto works in c++11 (this is a new feature to c++11, right?) Update: I revised the above to better clarify how my vector is really populated in a function, and I'm just trying to

C++11 auto: what if it gets a constant reference?

跟風遠走 提交于 2019-11-27 06:39:28
Please take a look at the following simple code: class Foo { public: Foo(){} ~Foo(){} Foo(const Foo&){} Foo& operator=(const Foo&) { return *this; } }; static Foo g_temp; const Foo& GetFoo() { return g_temp; } I tried to use auto like this: auto my_foo = GetFoo(); I expected that my_foo will be a constant reference to Foo , which is the return type of the function. However, the type of auto is Foo , not the reference. Furthermore, my_foo is created by copying g_temp . This behavior isn't that obvious to me. In order to get the reference to Foo , I needed to write like this: const auto& my_foo2

CSS Overflow属性详解

ε祈祈猫儿з 提交于 2019-11-27 06:14:48
检索或设置当对象的内容超过其指定高度及宽度时如何管理内容。 所有对象的默认值是 visible ,除了 textarea 对象和 body 对象的默认值是 auto 。设置 textarea 对象此属性值为 hidden 将隐藏其滚动条。 overflow属性有四个值: visible (默认), hidden , scroll , 和 auto 。 同样有两个overflow的姐妹属性overflow-y 和overflow-x,它们很少被采用。 1、Visible 如果你不设置overflow属性,则默认的overflow属性值就是visible。所以一般而言,并没有什么理由特别的设定overflow的属性为visible除非你想覆盖它在其它地方被设定的值。 这里需要记住的重要的事情是,尽管盒子外面的内容是可见的,内容并不会影响页面的工作流。比如: 一般来说,你至少不用为里面的内容为文字的盒子设置固定的高度,这样就不会遇到这种情况了。 2、Hidden 默认值visible的相反的值就是 hidden 。它会将所有超出盒子的所有内容都给隐藏掉。 这对应付使用动态的内容,而且可能会由于内容溢出而引起 一些布局上的问题 的确很有用。尽管如此,请记住用此方法隐藏的内容将彻底的看不到(除非去查看源代码)。 比如有的用户设置他们的浏览器的默认 字体 比你预期的要大些