Нет, это не будет работать по назначению; вы все равно получите копии. Я очень удивлен этим, так как я думал, что initializer_list
существует для хранения массива временных рядов, пока они не будут move
'd.
begin
и end
для initializer_list
return const T *
, поэтому результат move
в вашем коде T const &&
- неизменяемая ссылка rvalue. Из этого выражения нельзя толкнуть. Он будет привязан к функциональному параметру типа T const &
, потому что rvalues связывается с константными ссылками lvalue, и вы все равно увидите семантику копирования.
Вероятно, причина в том, что компилятор может выбрать, чтобы сделать initializer_list
статически инициализированная константа, но, похоже, было бы более чистым сделать свой тип initializer_list
или const initializer_list
по усмотрению компилятора, поэтому пользователь не знает, ожидать ли const
или изменяемого результата из begin
и end
.
Обновление: я написал предложение ISO для поддержки initializer_list
типов только для перемещения. , Это только первый проект, и он еще не реализован, но вы можете увидеть его для более подробного анализа проблемы.
Per this thread, R.styleable has been removed from android 1.5 and higher.
There are a number of ways to get the sample to work, the simplest that I found was recommended by Justin Anderson in the thread linked to above:
Create a new XML file called "resources.xml" with the following content:
Place the XML file in the res\values directory (alongside strings.xml)
Update the constructor for your ImageAdapter with the following (assuming the ImageAdapter class is defined in its own file):
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
This solution basically defines the styleable attribute as a resource of the app itself and gives it the necessary structure to work in the app. Note that the app can run fine if you just omit the two lines of code (prior to a.recycle();), all this code does is set a grey background around the images in the Gallery.
Причина этой проблемы в том, что ресурсы, которые они говорят вам поместить в res/values/attrs.xml, следующие:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="HelloGallery">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>
Но затем вы получаете этот адаптер, который Eclipse не может понять и, честно говоря, не имеет смысла:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
mGalleryItemBackground = a.getResourceId(
android.R.styleable.Theme_galleryItemBackground, 0);
a.recycle();
}
Это потому, что вы не должны иметь "android." перед ресурсами, название стилей здесь Theme, но HelloGallery в фактическом ресурсе, и galleryItemBackground помещает android между названием стиля и атрибутом, как это: Theme_android_galleryItemBackground
Поэтому, если вы хотите, чтобы метод ImageAdapter работал с предоставленными вам ресурсами, вы должны переписать его следующим образом:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
}
Для будущих проблем, связанных с ресурсами (ошибки типа R.* cannot be resolved), изучите /gen/R.java на предмет того, как на самом деле называются ресурсы.
В выбранном ответе есть небольшая ошибка, вместо этого есть стилизация с помощью styleable
Это должно выглядеть так:
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>