问:
horizontal direction of Floating action menu
I need a float action menu with horizontal direction, I found this library
but it's linked to listview and not what I look for, I tested 'com.github.clans:fab:1.6.4' it's really good but always no horizontal direction.

any idea to find out ?

答:
The easiest way to do without any library is to set one FAB visible and the other two invisible, and make the two visible on the click of first FAB. Adding some code snippets as i have used this type of FAB Styling, moreover you can add your animation to icons so give it feel good effect.

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentlayout"
android:background="#2a2a2a"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="160dp"
    android:visibility="invisible"
    android:layout_marginBottom="16dp"
    app:backgroundTint="@color/colorPrimary"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    android:src="@android:drawable/ic_menu_share" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="90dp"
    android:visibility="invisible"
    android:layout_marginBottom="16dp"
    app:elevation="6dp"
    app:backgroundTint="@color/colorPrimary"
    app:pressedTranslationZ="12dp"
    android:src="@android:drawable/ic_menu_search" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    app:elevation="6dp"
    app:backgroundTint="@color/colorPrimary"
    app:pressedTranslationZ="12dp"
    android:layout_margin="16dp"
    android:src="@android:drawable/ic_input_add" />
</code>```

And the usage in activity will be something like this.

```<code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Boolean isFabOpen = false;
private FloatingActionButton fab,fab1,fab2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fab = (FloatingActionButton)findViewById(R.id.fab);
    fab1 = (FloatingActionButton)findViewById(R.id.fab1);
    fab2 = (FloatingActionButton)findViewById(R.id.fab2);
    fab.setOnClickListener(this);
    fab1.setOnClickListener(this);
    fab2.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    int id = v.getId();
    switch (id){
        case R.id.fab:

            animateFAB();
            break;
        case R.id.fab1:
            break;
        case R.id.fab2:

            break;
    }
}
public void animateFAB(){

    if(isFabOpen){
       /* fab.startAnimation(rotate_backward);
        fab1.startAnimation(fab_close);
        fab2.startAnimation(fab_close);*/
        fab1.setClickable(false);
        fab2.setClickable(false);
        isFabOpen = false;

    } else {
       /* fab.startAnimation(rotate_forward);
        fab1.startAnimation(fab_open);
        fab2.startAnimation(fab_open);*/
        fab1.setClickable(true);
        fab2.setClickable(true);
        isFabOpen = true;
    }
}}
</code>```

Body:
The easiest way to do without any library is to set one FAB visible and the other two invisible, and make the two visible on the click of first FAB. Adding some code snippets as i have used this type of FAB Styling, moreover you can add your animation to icons so give it feel good effect.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentlayout"
android:background="#2a2a2a"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="160dp"
    android:visibility="invisible"
    android:layout_marginBottom="16dp"
    app:backgroundTint="@color/colorPrimary"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    android:src="@android:drawable/ic_menu_share" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="90dp"
    android:visibility="invisible"
    android:layout_marginBottom="16dp"
    app:elevation="6dp"
    app:backgroundTint="@color/colorPrimary"
    app:pressedTranslationZ="12dp"
    android:src="@android:drawable/ic_menu_search" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    app:elevation="6dp"
    app:backgroundTint="@color/colorPrimary"
    app:pressedTranslationZ="12dp"
    android:layout_margin="16dp"
    android:src="@android:drawable/ic_input_add" />

And the usage in activity will be something like this.

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Boolean isFabOpen = false;
private FloatingActionButton fab,fab1,fab2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fab = (FloatingActionButton)findViewById(R.id.fab);
    fab1 = (FloatingActionButton)findViewById(R.id.fab1);
    fab2 = (FloatingActionButton)findViewById(R.id.fab2);
    fab.setOnClickListener(this);
    fab1.setOnClickListener(this);
    fab2.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    int id = v.getId();
    switch (id){
        case R.id.fab:

            animateFAB();
            break;
        case R.id.fab1:
            break;
        case R.id.fab2:

            break;
    }
}
public void animateFAB(){

    if(isFabOpen){
       /* fab.startAnimation(rotate_backward);
        fab1.startAnimation(fab_close);
        fab2.startAnimation(fab_close);*/
        fab1.setClickable(false);
        fab2.setClickable(false);
        isFabOpen = false;

    } else {
       /* fab.startAnimation(rotate_forward);
        fab1.startAnimation(fab_open);
        fab2.startAnimation(fab_open);*/
        fab1.setClickable(true);
        fab2.setClickable(true);
        isFabOpen = true;
    }
}}


来源: stackexchange

问:
Post request with Phantomjs
I use the following Node.js module
https://www.npmjs.com/package/phantom

The problem is I don't know how to make a post request in order to login (or at least I need to fill the login form and click the button).

How can I do it? If not possible, is there any Node.js module that can be used to make post request or click a button on the page

答: First, you have to download PhantomJS from here. Install it and then move the executable from the bin folder to the PATH of your file. Finally, open a new file, paste this code, and run from your command prompt: phantomjs [name of your file].

ContentLicense: CC BY-SA 3.0

Title: Post request with Phantomjs


问:
Append element to a list based on the values of the nested list
I want to append the values of the specific indices of a nested list based on the values of the same list but on different indices.

So, basically, if my initial list looks like the following:

a = [(1,2,1,[1,2,3]) , (1,2,2,[3,2,4]) , (1,2,3,[7,3,4]) , (1,2,3,[11,2,7]) ,..., (2,1,1,[5,6,3]) , (2,1,2,[3,1,8]) , ...]

I would like to firstly have a list of all the values of the 3rd index of the list a, which share the same value of the 1st and 2nd index in the list a. So, the 1st output will look like the following:

b = [[1,2,3] , [3,2,4] , [7,3,4] , [11,2,7]]

Then, I would like to run some calculations on the output, save the data and get the other set of data that share the same value of the 1st and 2nd index from the initial list (list a).

This process should be repeated for all the values of the initial list, till there is non left in that list.

With the following code, I get the 1st set of data, but I face problems to get the next set:

```<code>od = 1

ri = 1

q=0

for i in range(len(a)):

    while q<len(a):

        if a[q][0]==od and a[q][1]==ri:

            b.append(Net_info[q][3])

        q+=1
    ri += 1

od += 1
</code>```

Body:
I want to append the values of the specific indices of a nested list based on the values of the same list but on different indices.

So, basically, if my initial list looks like the following:

a = [(1,2,1,[1,2,3]) , (1,2,2,[3,2,4]) , (1,2,3,[7,3,4]) , (1,2,3,[11,2,7]) ,..., (2,1,1,[5,6,3]) , (2,1,2,[3,1,8]) , ...]

I would like to firstly have a list of all the values of the 3rd index of the list a, which share the same value of the 1st and 2nd index in the list a. So, the 1st output will look like the following:

b = [[1,2,3] , [3,2,4] , [7,3,4] , [11,2,7]]

Then, I would like to run some calculations on the output, save the data and get the other set of data that share the same value of the 1st and 2nd index from the initial list (list a).

This process should be repeated for all the values of the initial list, till there is non left in that list.

With the following code, I get the 1st set of data, but I face problems to get the next set:

od = 1

ri = 1

q=0

for i in range(len(a)):

    while q<len(a):

        if a[q][0]==od and a[q][1]==ri:

            b.append(Net_info[q][3])

        q+=1
    ri += 1

od += 1

Body:
>>> data = dict()
>>> a = [(1, 2, 1, [1, 2, 3]), (1, 2, 2, [3, 2, 4]), (1, 2, 3, [7, 3, 4]), (1, 2, 3, [11, 2, 7]), (2, 1, 1, [5, 6, 3]), (2, 1, 2, [3, 1, 8])]
>>> for d in a:
...     data.setdefault(d[:2], []).append(d[3])

>>> data
{(1, 2): [[1, 2, 3], [3, 2, 4], [7, 3, 4], [11, 2, 7]], (2, 1): [[5, 6, 3], [3, 1, 8]]}
>>> output = data.values()
[[[5, 6, 3], [3, 1, 8]], [[1, 2, 3], [3, 2, 4], [7, 3, 4], [11, 2, 7]]]

try this snippet, hope this helps


问:
How to know if song available in a country or not
How can I find out if a song is available in a country or not so I can enable/disable features of my app based on this information using the Android Spotify SDK or web API.</p>

答:
Have to use the web-api

I found this forum post that helped me find the answer on a forum post in quora with the title "What website lists Spotify music availability per country"
I would have linked it but I don't have enough reputation to post more than 2 links.

Go to for an explanation of the features available through the web-api
https://developer.spotify.com/web-api/migration-guide/

Can test looking up track availability at this link
https://developer.spotify.com/web-api/console/get-track/#complete


问:
Changing logging levels localized name with jdk logging/slf4j
I see that logging levels using jdk logging are localized, running this example:

```<code>package com.stackoverflow.tests.logging;

import java.util.Locale;
import java.util.logging.Logger;

public class TestLogging
{

    public static void doLog(Locale l)
    {
        Locale.setDefault(l);

        Logger logger = Logger.getLogger(TestLogging.class.getName());

        final String msg = "Hello logging world";
        logger.severe(msg);
        logger.info(msg);
        logger.config(msg);
        logger.fine(msg);
        logger.finer(msg);
        logger.finest(msg);

    }

    public static void main(String args[])
    {

        doLog(Locale.ITALY);

    //  doLog(Locale.UK);

    //  doLog(Locale.FRANCE);

    }
}
</code>```

Ouput for italian (using default logger configuration hence only severe and info levels are logged)

```<code>dic 15, 2014 10:48:43 AM com.stackoverflow.tests.logging.TestLogging doLog
Grave: Hello logging world
dic 15, 2014 10:48:43 AM com.stackoverflow.tests.logging.TestLogging doLog
Informazioni: Hello logging world
</code>```

I would like to set up custom localized message for logging levels instead of the one provided by default.

How can I do that

Using JDK logging directly (I see Logger.getLogger can take a ResourceBundle but I did not manage to make it work, and also I dont know what is expected to be in this file)

Using SLF4 facade (I guess that would imply tweaking LoggerFactory.getLogger function of SLF4J which is the one I'm using to obtain the loggers)

答:
In java.util.logging, you can define your own levels using a different bundle name or none at all. The way to do that is subclassing java.util.logging.Level and adding your own constants. For example, if you want non-localized names, you can create your levels as follows:

```<code>public class Level extends java.util.logging.Level {
    private static final long serialVersionUID = -1283674772992561191L;

    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE);
    public static final Level SEVERE = new Level("SEVERE", 1000);
    public static final Level WARNING = new Level("WARNING", 900);
    public static final Level INFO = new Level("INFO", 800);
    public static final Level CONFIG = new Level("CONFIG", 700);
    public static final Level FINE = new Level("FINE", 500);
    public static final Level FINER = new Level("FINER", 400);
    public static final Level FINEST = new Level("FINEST", 300);
    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE);

    protected Level(String name, int value) {
        super(name, value);
    }
}
</code>```

If you want to use another bundle name, do the following:

```<code>public class Level extends java.util.logging.Level {
    private static final long serialVersionUID = -1283674772992561191L;

    static final String my_bundle_name = "my.bundle.name";

    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE, my_bundle_name);
    public static final Level SEVERE = new Level("SEVERE", 1000, my_bundle_name);
    public static final Level WARNING = new Level("WARNING", 900, my_bundle_name);
    public static final Level INFO = new Level("INFO", 800, my_bundle_name);
    public static final Level CONFIG = new Level("CONFIG", 700, my_bundle_name);
    public static final Level FINE = new Level("FINE", 500, my_bundle_name);
    public static final Level FINER = new Level("FINER", 400, my_bundle_name);
    public static final Level FINEST = new Level("FINEST", 300, my_bundle_name);
    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE, my_bundle_name);

    protected Level(String name, int value, String resourceBundleName) {
        super(name, value, resourceBundleName);
    }
}
</code>```

Of course, you must use your custom levels instead of the default ones, so you must use calls like Logger.log(Level level, String msg), where you specify the level explicitly, instead of Logger.info(String msg), that always uses the default level.

EDIT: I got the idea from https://docs.oracle.com/javase/8/docs/api/java/util/logging/Level.html#Level-java.lang.String-int-

Body:
I see that logging levels using jdk logging are localized, running this example:

package com.stackoverflow.tests.logging;

import java.util.Locale;
import java.util.logging.Logger;

public class TestLogging
{

    public static void doLog(Locale l)
    {
        Locale.setDefault(l);

        Logger logger = Logger.getLogger(TestLogging.class.getName());

        final String msg = "Hello logging world";
        logger.severe(msg);
        logger.info(msg);
        logger.config(msg);
        logger.fine(msg);
        logger.finer(msg);
        logger.finest(msg);

    }

    public static void main(String args[])
    {

        doLog(Locale.ITALY);

    //  doLog(Locale.UK);

    //  doLog(Locale.FRANCE);

    }
}

Ouput for italian (using default logger configuration hence only severe and info levels are logged)

dic 15, 2014 10:48:43 AM com.stackoverflow.tests.logging.TestLogging doLog
Grave: Hello logging world
dic 15, 2014 10:48:43 AM com.stackoverflow.tests.logging.TestLogging doLog
Informazioni: Hello logging world

I would like to set up custom localized message for logging levels instead of the one provided by default.

How can I do that

Using JDK logging directly (I see Logger.getLogger can take a ResourceBundle but I did not manage to make it work, and also I dont know what is expected to be in this file)

Using SLF4 facade (I guess that would imply tweaking LoggerFactory.getLogger function of SLF4J which is the one I'm using to obtain the loggers)

Body:
In java.util.logging, you can define your own levels using a different bundle name or none at all. The way to do that is subclassing java.util.logging.Level and adding your own constants. For example, if you want non-localized names, you can create your levels as follows:

public class Level extends java.util.logging.Level {
    private static final long serialVersionUID = -1283674772992561191L;

    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE);
    public static final Level SEVERE = new Level("SEVERE", 1000);
    public static final Level WARNING = new Level("WARNING", 900);
    public static final Level INFO = new Level("INFO", 800);
    public static final Level CONFIG = new Level("CONFIG", 700);
    public static final Level FINE = new Level("FINE", 500);
    public static final Level FINER = new Level("FINER", 400);
    public static final Level FINEST = new Level("FINEST", 300);
    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE);

    protected Level(String name, int value) {
        super(name, value);
    }
}

If you want to use another bundle name, do the following:

public class Level extends java.util.logging.Level {
    private static final long serialVersionUID = -1283674772992561191L;

    static final String my_bundle_name = "my.bundle.name";

    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE, my_bundle_name);
    public static final Level SEVERE = new Level("SEVERE", 1000, my_bundle_name);
    public static final Level WARNING = new Level("WARNING", 900, my_bundle_name);
    public static final Level INFO = new Level("INFO", 800, my_bundle_name);
    public static final Level CONFIG = new Level("CONFIG", 700, my_bundle_name);
    public static final Level FINE = new Level("FINE", 500, my_bundle_name);
    public static final Level FINER = new Level("FINER", 400, my_bundle_name);
    public static final Level FINEST = new Level("FINEST", 300, my_bundle_name);
    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE, my_bundle_name);

    protected Level(String name, int value, String resourceBundleName) {
        super(name, value, resourceBundleName);
    }
}

Of course, you must use your custom levels instead of the default ones, so you must use calls like Logger.log(Level level, String msg), where you specify the level explicitly, instead of Logger.info(String msg), that always uses the default level.

EDIT: I got the idea from https://docs.oracle.com/javase/8/docs/api/java/util/logging/Level.html#Level-java.lang.String-int-


问:
Host machine cannot access nginx virtual hosts on the guest machine
Question: how to create simple nginx config that will read folders structure as domains (test.local, myblog.local) and shows the page from this folders, including PHP?

Information:
Windows 10 x64 build

Vagrant 1.9.5

VirtualBox 5.0.22 (latest)

Guest OS: Ubuntu Xenial x64 latest

So, i want to create simple nginx config, that will recreate folder structure. See
my config file on pastebin.

Also here is a Vagrantfile config, which use SMB to mount a folder.

The structure of folders:

```<code>├───devhost.local
│   ├───log
│   └───public
│           index.html
│           index.php
│
└───test.local
    ├───log
    └───public
            index.html
</code>```

The rights for files and folders for devhost:

```<code>ubuntu@ubuntu-xenial:~$ ls -la /var/www/html/devhost.local/
total 4
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 .
drwxr-xr-x 2 ubuntu www-data 4096 Jun  7 12:44 ..
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 log
drwxr-xr-x 2 ubuntu www-data    0 Jun  6 14:13 public
</code>```

My hosts file in Windows:

```<code>192.168.33.10   devhost.local
</code>```

So, when i have default config in my sites-enabled folder i can open guest machine through 192.168.33.10 and i see html page of nginx, but when i remove this default config and enable my wildcard config (see link my config file) so i cannot access my domains. The sudo nginx -t says that everything is ok, also i tried to restart my guest machine, reload/restart nginx service. Also, i disable Windows 10 Firewall (i dont know if its disabled fully, but says that its disabled). Also, the log files is empty and even not created, both access log and error log.

Where is my mistake? If need more information, please, ask me, i will give.

Thanks a lot!

答:
I found the solution.

First of all, when i keep only one file with config, my nginx doesnt listen port 80, i check sudo netstat -ntlp | grep LISTEN but there wasnt port 80. So i Google, and found another question on stackoverflow (see link at the end).

Solution: recreate the simlink to my file with config, after that when i run sudo nginx -t i see a few errors. So its seems that before this files was empty or something like that, but i didnt notice this because i edit file directly in sites-available folder.

Thanks to everybody!

This question helps me to solve the problem: nginx not listening to port 80

Body:
Question: how to create simple nginx config that will read folders structure as domains (test.local, myblog.local) and shows the page from this folders, including PHP?

Information:
Windows 10 x64 build

Vagrant 1.9.5

VirtualBox 5.0.22 (latest)

Guest OS: Ubuntu Xenial x64 latest

So, i want to create simple nginx config, that will recreate folder structure. See
my config file on pastebin.

Also here is a Vagrantfile config, which use SMB to mount a folder.

The structure of folders:

├───devhost.local
│   ├───log
│   └───public
│           index.html
│           index.php
│
└───test.local
    ├───log
    └───public
            index.html

The rights for files and folders for devhost:

ubuntu@ubuntu-xenial:~$ ls -la /var/www/html/devhost.local/
total 4
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 .
drwxr-xr-x 2 ubuntu www-data 4096 Jun  7 12:44 ..
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 log
drwxr-xr-x 2 ubuntu www-data    0 Jun  6 14:13 public

My hosts file in Windows:

192.168.33.10   devhost.local

So, when i have default config in my sites-enabled folder i can open guest machine through 192.168.33.10 and i see html page of nginx, but when i remove this default config and enable my wildcard config (see link my config file) so i cannot access my domains. The sudo nginx -t says that everything is ok, also i tried to restart my guest machine, reload/restart nginx service. Also, i disable Windows 10 Firewall (i dont know if its disabled fully, but says that its disabled). Also, the log files is empty and even not created, both access log and error log.

Where is my mistake? If need more information, please, ask me, i will give.

Thanks a lot!


问:
Reduce redundant SQLite nested query?
How can I reduce this nested query so that X,Y,Z are filtered prior to checking AA?
This works but is expensive since it calculates X,Y,Z for each subquery.
Only AA needs to be checked in each.</p>

```<code>SELECT 3*b3.bin3 + 2*b2.bin2 + b1.bin1 FROM
  (SELECT count(*) AS bin1 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 1 AND `AA` <= 2) b1
  JOIN
  (SELECT count(*) AS bin2 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 2.01 AND `AA` <= 3) b2
  JOIN
  (SELECT count(*) AS bin3 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 3.01 AND `AA` <= 4) b3;
</code>```

答:
are you on SQL 2008? you might be able to use with as. Try this</p>

```<code>With b as
(
Select
*
from TD
where
x=1 and
y >= 2 and
z >= 2)

SELECT 3*b3.bin3 + 2*b2.bin2 + b1.bin1 FROM

(select
count ()
from b
where AA >= 1 and AA <= 2) bin1
join

(select
count ()
from b
where AA >= 2.01 and AA <= 3) bin2
join

(select
count ()
from b
where AA >= 3.01 and AA <= 4) bin3
</code>```

Title: Reduce redundant SQLite nested query?

Body:
How can I reduce this nested query so that X,Y,Z are filtered prior to checking AA?
This works but is expensive since it calculates X,Y,Z for each subquery.
Only AA needs to be checked in each.

SELECT 3*b3.bin3 + 2*b2.bin2 + b1.bin1 FROM
  (SELECT count(*) AS bin1 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 1 AND `AA` <= 2) b1
  JOIN
  (SELECT count(*) AS bin2 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 2.01 AND `AA` <= 3) b2
  JOIN
  (SELECT count(*) AS bin3 FROM `TD` WHERE
  `X` = 1 AND
  `Y` >= 2 AND
  `Z` >= 2 AND
  `AA` >= 3.01 AND `AA` <= 4) b3;

Body:
are you on SQL 2008? you might be able to use with as. Try this

With b as
(
Select
*
from TD
where
x=1 and
y >= 2 and
z >= 2)

SELECT 3*b3.bin3 + 2*b2.bin2 + b1.bin1 FROM

(select
count ()
from b
where AA >= 1 and AA <= 2) bin1
join

(select
count ()
from b
where AA >= 2.01 and AA <= 3) bin2
join

(select
count ()
from b
where AA >= 3.01 and AA <= 4) bin3


问:
Symfony2 / File Upload - guessExtension on null if file field is empty
I have file field with required = false, multiple=multiple. Everything works fine, but if file input is empty, symfony2 show me this error.

Error: Call to a member function guessExtension() on null

Here is my form type:

```<code>->add('file', 'file', array(
                'multiple' => 'multiple',
                'data_class' => null,
                'required' => false,
                'mapped' => false,
                'attr' => array(
                    'maxSize' => '1024k',
                    'accept' => 'image/*',
                )
            ))
</code>```

Upload function:

```<code>private function uploadImg($files)
    {
        $path = array();
        foreach ($files as $file) {
            $extension = $file->guessExtension();
            if (!$extension) {
                $extension = 'bin';
            }
            $randomName = 'image' . date('Y-m-d-H-i-s') . uniqid() . '.' . $extension;
            $file->move('uploads/images/', $randomName);
            $path[] = $randomName;
        }
        return $path;
    }
</code>```

How can I check if file input is empty?

$form['file']->getData(); every time returns Array

答:
For Symfony 3, I used this method and working fine.</p>

```<code>use Symfony\Component\HttpFoundation\File\UploadedFile;

public function updateAction(...){
  // $image is Entity property, change accordingly.
  $file = $item->getImage();
  if ($file instanceof UploadedFile) {
     ... upload code
  }
}
</code>```

Body:
I have file field with required = false, multiple=multiple. Everything works fine, but if file input is empty, symfony2 show me this error.

Error: Call to a member function guessExtension() on null

Here is my form type:

->add('file', 'file', array(
                'multiple' => 'multiple',
                'data_class' => null,
                'required' => false,
                'mapped' => false,
                'attr' => array(
                    'maxSize' => '1024k',
                    'accept' => 'image/*',
                )
            ))

Upload function:

private function uploadImg($files)
    {
        $path = array();
        foreach ($files as $file) {
            $extension = $file->guessExtension();
            if (!$extension) {
                $extension = 'bin';
            }
            $randomName = 'image' . date('Y-m-d-H-i-s') . uniqid() . '.' . $extension;
            $file->move('uploads/images/', $randomName);
            $path[] = $randomName;
        }
        return $path;
    }

How can I check if file input is empty?

$form['file']->getData(); every time returns Array

Body:
For Symfony 3, I used this method and working fine.

use Symfony\Component\HttpFoundation\File\UploadedFile;

public function updateAction(...){
  // $image is Entity property, change accordingly.
  $file = $item->getImage();
  if ($file instanceof UploadedFile) {
     ... upload code
  }
}


问:
Usage of this next_combination code
Currently I am trying to generate combinations from a vector that contains some integers. For now I want it to print out all of the combinations that are of length to_generate.
I found this code at combination and permutation in C++ that uses std::next_permutation to generate combinations. The next_combination code is as follows:

```<code>template<class RandIt, class Compare>
bool next_combination(RandIt first, RandIt mid, RandIt last, Compare comp)
{
    std::sort(mid, last, std::tr1::bind(comp, std::tr1::placeholders::_2
                                        , std::tr1::placeholders::_1));
    return std::next_permutation(first, last, comp);
}
</code>```

I tried to call it like this:

```<code>bool mycomp (int c1, int c2)
{ return (c1)<(c2); }

void test_combos(int to_generate){
    std::vector<int> combo(30);
    for(int i=0;i<30;++i){
        combo.push_back(i);
    }
    while(next_combination<std::vector<int>::iterator,   bool>(combo.begin(),combo.begin()+to_generate,combo.end(),mycomp)){
        for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter){
            std::cout << *iter << " ";
        }
    }
}
</code>```

but I get a huge stl garbled error message. Is there anything really obvious going wrong here?

Which headers can I find std::placeholder?

As requested, here is the error message:

```
$ make
g++ -g -std=c++0x -I /usr/lib/ -c equity.cpp
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘bool std::next_permutation(_BIter, _BIter, _Compare) [with _BIter = __gnu_cxx::__normal_iterator > >, _Compare = bool]’:
misc.hpp:15:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:3655: error: ‘__comp’ cannot be used as a function
/usr/include/c++/4.4/bits/stl_algo.h:3658: error: ‘__comp’ cannot be used as a function
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:124: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:125: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:127: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:131: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:133: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2230: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h:2233: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2128: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:1919: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__unguarded_linear_insert(_RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2134:   instantiated from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2084: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
In file included from /usr/include/c++/4.4/bits/stl_algo.h:62,
                 from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:303: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:316:   instantiated from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:180: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
make: *** [equity.o] Error 1
```

答:
The second template argument shouldn't be bool. You can allow compiller to handle types and simply write:

```<code>while(next_combination(combo.begin(), combo.begin() + to_generate, combo.end(), std::less<int>()))
    for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter)
        std::cout << *iter << " ";
</code>```

And use spaces - it makes code look better.

ContentLicense: CC BY-SA 2.5

Title: Usage of this next_combination code

Body:
Currently I am trying to generate combinations from a vector that contains some integers. For now I want it to print out all of the combinations that are of length to_generate.
I found this code at combination and permutation in C++ that uses std::next_permutation to generate combinations. The next_combination code is as follows:

template<class RandIt, class Compare>
bool next_combination(RandIt first, RandIt mid, RandIt last, Compare comp)
{
    std::sort(mid, last, std::tr1::bind(comp, std::tr1::placeholders::_2
                                        , std::tr1::placeholders::_1));
    return std::next_permutation(first, last, comp);
}

I tried to call it like this:

bool mycomp (int c1, int c2)
{ return (c1)<(c2); }

void test_combos(int to_generate){
    std::vector<int> combo(30);
    for(int i=0;i<30;++i){
        combo.push_back(i);
    }
    while(next_combination<std::vector<int>::iterator,   bool>(combo.begin(),combo.begin()+to_generate,combo.end(),mycomp)){
        for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter){
            std::cout << *iter << " ";
        }
    }
}

but I get a huge stl garbled error message. Is there anything really obvious going wrong here?

Which headers can I find std::placeholder?

As requested, here is the error message:

$ make
g++ -g -std=c++0x -I /usr/lib/ -c equity.cpp
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘bool std::next_permutation(_BIter, _BIter, _Compare) [with _BIter = __gnu_cxx::__normal_iterator > >, _Compare = bool]’:
misc.hpp:15:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:3655: error: ‘__comp’ cannot be used as a function
/usr/include/c++/4.4/bits/stl_algo.h:3658: error: ‘__comp’ cannot be used as a function
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:124: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:125: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:127: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:131: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:133: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2230: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h:2233: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2128: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:1919: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__unguarded_linear_insert(_RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2134:   instantiated from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2084: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
In file included from /usr/include/c++/4.4/bits/stl_algo.h:62,
                 from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:303: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:316:   instantiated from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:180: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
make: *** [equity.o] Error 1

Body:
The second template argument shouldn't be bool. You can allow compiller to handle types and simply write:

while(next_combination(combo.begin(), combo.begin() + to_generate, combo.end(), std::less<int>()))
    for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter)
        std::cout << *iter << " ";

And use spaces - it makes code look better.


问:
How to set a command as a dependency in waf
I have a waf rule that does not create a file, so I don't have a target. I'd like another waf rule to be run strictly after the first rule. Below is a contrived example of this type of situation.

In Make syntax, I'm trying to do something like the following:

```<code>kill_server:
     myserver --kill

install_server: kill_server
     cp $(SRC)/myserver $(BLD)/myserver
</code>```

In waf, I'm here:

 def install_server(bld):
      killer = bld(name='kill_server', rule='myserver --kill')
      bld(name='install_server', rule='cp ${SRC} ${TGT}',
          source=os.path.join(src, 'myserver'),
          target=os.path.join(bld, 'myserver'), deps=[killer])
```

Obviously this doesn't work, because killer is TaskGen, not a target node. What could I put in deps? Can a step depend on another step that doesn't create a target?

答:
For rule based task generator, you can use the after keyword:

def build(bld):

    bld(
        name = 'kill_server',
        rule = 'echo killing ...;sleep 5',
    )

    bld(
        name = 'install_server',
        rule = 'cp ${SRC} ${TGT}',
        source = 'myserver',
        target = 'myserver2',
        after = ["kill_server"]
    )
```

<p>It works as rule based TG generate only one task with the TG name, and the <code>after</code> keyword is used for the task.</p>

<p>Another solution for other TG is to generate an output file and use it as a source for the dependant TG.</p>

<p>If source and target are the same, use waf Node API:</p>

```server = bld.path.find_node('myserver')
target_server = server.get_bld()
```

waf automatically manage the source tree vs the build tree.

Body:
I have a waf rule that does not create a file, so I don't have a target. I'd like another waf rule to be run strictly after the first rule. Below is a contrived example of this type of situation.

In Make syntax, I'm trying to do something like the following:

kill_server:
     myserver --kill

install_server: kill_server
     cp $(SRC)/myserver $(BLD)/myserver

In waf, I'm here:

 def install_server(bld):
      killer = bld(name='kill_server', rule='myserver --kill')
      bld(name='install_server', rule='cp ${SRC} ${TGT}',
          source=os.path.join(src, 'myserver'),
          target=os.path.join(bld, 'myserver'), deps=[killer])

Obviously this doesn't work, because killer is TaskGen, not a target node. What could I put in deps? Can a step depend on another step that doesn't create a target?

Body:
For rule based task generator, you can use the after keyword:

def build(bld):

    bld(
        name = 'kill_server',
        rule = 'echo killing ...;sleep 5',
    )

    bld(
        name = 'install_server',
        rule = 'cp ${SRC} ${TGT}',
        source = 'myserver',
        target = 'myserver2',
        after = ["kill_server"]
    )

It works as rule based TG generate only one task with the TG name, and the after keyword is used for the task.

Another solution for other TG is to generate an output file and use it as a source for the dependant TG.

If source and target are the same, use waf Node API:

server = bld.path.find_node('myserver')
target_server = server.get_bld()

waf automatically manage the source tree vs the build tree.


问:
How can I send parameter in modal bootstrap?
My view is like this :

```<code>@foreach($product->photo_list as $i => $photo)
    <a href="javascript:" class="text-danger delete"
       data-toggle="modal"
       data-target="#modal-delete-image"
       data-photo="{{ json_encode($photo) }}"
       data-product_id="{{ $product->id }}"
    >
        <span class="fa fa-trash"></span>
    </a>
@endforeach
</code>```

My modal is like this :

```<code><bs-modal id="modal-delete-image" v-cloak>
    <h4 slot="title" class="modal-title">...</h4>
    <div slot="body" class="modal-body">
       ...
    </div>
    <div slot="footer" class="modal-footer">
        <button type="button" class="btn btn-danger" id="confirm-delete">
            Delete
        </button>
    </div>
</bs-modal>
</code>```

My javascript is like this :

```<code>$('.delete').click(function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    $('#confirm-delete').data('photo', photo, 'productId', productId); //set the data attribute on the modal button
});

$('#confirm-delete').click(function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    console.log(photo)
    console.log(productId)
    $.ajax({
        ...
    });
});
</code>```

When the code executed, the result of console log is

undefined

How can I solve this problem?

答:
you can use this</p>

```<code><button data-photo="photo" data-photo_id="photo-id" type="button" class="btn btn-danger" id="confirm-delete">
    Delete
</button>

$('.delete').on("click",function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    $('#confirm-delete').data('photo', photo);
    $('#confirm-delete').data('productId', productId);
});

$('#confirm-delete').on("click",function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    console.log(photo)
    console.log(productId)
    $.ajax({
        ...
    });
});
</code>```

Body:
My view is like this :

@foreach($product->photo_list as $i => $photo)
    id }}"
    >

@endforeach

My modal is like this :

<bs-modal id="modal-delete-image" v-cloak>

...

       ...

        <button type="button" class="btn btn-danger" id="confirm-delete">
            Delete
        </button>

</bs-modal>

My javascript is like this :

$('.delete').click(function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    $('#confirm-delete').data('photo', photo, 'productId', productId); //set the data attribute on the modal button
});

$('#confirm-delete').click(function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    console.log(photo)
    console.log(productId)
    $.ajax({
        ...
    });
});

When the code executed, the result of console log is

undefined

How can I solve this problem?

Body:
you can use this

<button data-photo="photo" data-photo_id="photo-id" type="button" class="btn btn-danger" id="confirm-delete">
    Delete
</button>

$('.delete').on("click",function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    $('#confirm-delete').data('photo', photo);
    $('#confirm-delete').data('productId', productId);
});

$('#confirm-delete').on("click",function(){
    var photo = $(this).data('photo');
    var productId = $(this).data('product_id');
    console.log(photo)
    console.log(productId)
    $.ajax({
        ...
    });
});


问:
C99 standard and gnu libc printf
the c99 standard (ISO/IEC 9899:1999) says that the length field of pintf format placeholder can be L, that apply only to float number. Thi is confirmed also in printf(3) manpage:

L

A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument.

If I compile this:

```<code>printf("%Ld",3);
</code>```

using -std=c99 gcc argument, I get a warning:

```<code>warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
  printf("%Ld",3);
           ^
</code>```

It seems that gnu libc does not folloe c99 standard

I have gcc 6.3.0, gnu libc 2.24, my host is a linux ubuntu 17.04 64bit

[Edited]

if I compile this:

```<code>printf("%Ld\n",3);
printf("%lld\n", 3LL);
printf("%Lf\n", 3.3L);
printf("%llf\n", 3.3L);
printf("%f\n", 3.3L);
</code>```

I get:

```<code>warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
  printf("%Ld\n",3);
            ^
warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
  printf("%llf\n", 3.3L);
             ^
warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
  printf("%f\n", 3.3L);
           ^
</code>```

So the expected warning message is like for %llf.

with -pedantic I get more verbose messages:

```<code>warning: ISO C does not support the ‘%Ld’ gnu_printf format [-Wformat=]
  printf("%Ld\n",3);
            ^
 warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
 warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
   printf("%llf\n", 3.3L);
              ^
 warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
   printf("%f\n", 3.3L);
            ^
</code>```

[Edited]

I have a mail from gcc ML

it looks that '%Ld' is allowed and require
    ‘long long int’.

But it is allowed by GNU libc, that's the point. For GNU libc %Ld
  means the same as %lld, but that's non-standard, so when you use
  -pedantic you get a warning.

And this explain the warning message.

答:
The standard says:

If a length modifier appears with any conversion specifier other than as specified above, the behavior is undefined.

In this case, the L length modifier is not specified for use with the d conversion specifier, so the behavior is undefined.

Presumably gcc (this is gcc giving you the warning, not libc) is using the same internal flag for long doubles and long long ints. It would be nice if the warning were more precise, but it isn't required to give you any warning at all (or to do anything else in particular), so it's following the standard correctly.

Title: C99 standard and gnu libc printf

Body:
the c99 standard (ISO/IEC 9899:1999) says that the length field of pintf format placeholder can be L, that apply only to float number. Thi is confirmed also in printf(3) manpage:

L

A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument.

If I compile this:

printf("%Ld",3);

using -std=c99 gcc argument, I get a warning:

warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
  printf("%Ld",3);
           ^

It seems that gnu libc does not folloe c99 standard

I have gcc 6.3.0, gnu libc 2.24, my host is a linux ubuntu 17.04 64bit

[Edited]

if I compile this:

printf("%Ld\n",3);
printf("%lld\n", 3LL);
printf("%Lf\n", 3.3L);
printf("%llf\n", 3.3L);
printf("%f\n", 3.3L);

I get:

warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
  printf("%Ld\n",3);
            ^
warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
  printf("%llf\n", 3.3L);
             ^
warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
  printf("%f\n", 3.3L);
           ^

So the expected warning message is like for %llf.

with -pedantic I get more verbose messages:

warning: ISO C does not support the ‘%Ld’ gnu_printf format [-Wformat=]
  printf("%Ld\n",3);
            ^
 warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
 warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
   printf("%llf\n", 3.3L);
              ^
 warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
   printf("%f\n", 3.3L);
            ^

[Edited]

I have a mail from gcc ML

it looks that '%Ld' is allowed and require
    ‘long long int’.

But it is allowed by GNU libc, that's the point. For GNU libc %Ld
  means the same as %lld, but that's non-standard, so when you use
  -pedantic you get a warning.

And this explain the warning message.


问:
Fetch First 'Variable' Rows Only
It is possible to pass value into fetch first syntax?</p>

```<code>        SET inputtotalCount = inputcount - inputintSimilarityLevel;
        IF inputtotalCount > 0 THEN
            BEGIN
                DELETE FROM EUSYSUPW WHERE UPRECID IN (
                SELECT UPRECID FROM EUSYSUPW
                WHERE UPUSRID = inputSACUSRID
                ORDER BY UPMODDT ASC
                FETCH FIRST inputtotalCount ROWS ONLY);
            END;
        END IF;
</code>```

答:
You can use global variable too :</p>

```<code>--Declare a global variable
CREATE OR REPLACE VARIABLE MyVar INTEGER DEFAULT 15;

--Modify value if necessary (you can do a calcul too)
SET MyVar=27;

--Delete in function of global variable
DELETE FROM EUSYSUPW f1
WHERE exists
(
  select * from
  (
       select f2.UPRECID, rownumber() over(order by f2.UPMODDT ASC) rang from EUSYSUPW f2
  ) f3
  where f1.UPRECID=f3.UPRECID and f3.rang=MyVar

);
</code>```

Title: Fetch First 'Variable' Rows Only

Body:
It is possible to pass value into fetch first syntax?

        SET inputtotalCount = inputcount - inputintSimilarityLevel;
        IF inputtotalCount > 0 THEN
            BEGIN
                DELETE FROM EUSYSUPW WHERE UPRECID IN (
                SELECT UPRECID FROM EUSYSUPW
                WHERE UPUSRID = inputSACUSRID
                ORDER BY UPMODDT ASC
                FETCH FIRST inputtotalCount ROWS ONLY);
            END;
        END IF;

Body:
You can use global variable too :

--Declare a global variable
CREATE OR REPLACE VARIABLE MyVar INTEGER DEFAULT 15;

--Modify value if necessary (you can do a calcul too)
SET MyVar=27;

--Delete in function of global variable
DELETE FROM EUSYSUPW f1
WHERE exists
(
  select * from
  (
       select f2.UPRECID, rownumber() over(order by f2.UPMODDT ASC) rang from EUSYSUPW f2
  ) f3
  where f1.UPRECID=f3.UPRECID and f3.rang=MyVar

);


答:
```<code>library(dplyr)
df %>% select(starts_with("best..F"))
</code>```

Title: how to search and retrieve specific columns from a huge data

Body:
I have a data looks like this

df<- structure(list(X..taminn = c(86L, 102L, 34L, 35L, 53L, 54L, 43L,
31L, 62L, 54L), X..turtia = c(413L, 322L, 525L, 535L, 247L, 207L,
241L, 440L, 189L, 221L), X..bestt = c(82L, 102L, 6L, 2L, 46L,
1L, 39L, 7L, 62L, 54L), Best..F1..129..test = c(3079.3, 1512.9,
497, 2804.5, 1353.7, 1597.6, 2005.1, 186.4, 1847.5, 1558.2),
    best..F1..130..test = c(8972.7, 1944, 2022.7, 13001.7, 2085,
    3228.6, 4948.5, 943.6, 1329, 2655.9), best..F1..131..test = c(2634.4,
    1181.3, 505.2, 2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2,
    1219), how1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
    2L, 1L), .Label = c("", "High", "Not Found"), class = "factor"),
    how2 = structure(c(2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 1L
    ), .Label = c("", "High", "Not Found"), class = "factor"),
    how3 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L
    ), .Label = c("", "High"), class = "factor"), Best.test...F1..129..test = c(3079.3,
    1512.9, 497, 2804.5, 1353.7, 1597.6, 2005.1, 186.4, 1847.5,
    1558.2), best.test...F1..130..test = c(8972.7, 1944, 2022.7,
    13001.7, 2085, 3228.6, 4948.5, 943.6, 1329, 2655.9), best.test...F1..131..test = c(2634.4,
    1181.3, 505.2, 2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2,
    1219), Best..test..129..test = c(3079.3, 1512.9, 497, 2804.5,
    1353.7, 1597.6, 2005.1, 186.4, 1847.5, 1558.2), best..test..130..test = c(8972.7,
    1944, 2022.7, 13001.7, 2085, 3228.6, 4948.5, 943.6, 1329,
    2655.9), best..test..131..test = c(2634.4, 1181.3, 505.2,
    2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2, 1219)), .Names = c("X..taminn",
"X..turtia", "X..bestt", "Best..F1..129..test", "best..F1..130..test",
"best..F1..131..test", "how1", "how2", "how3", "Best.test...F1..129..test",
"best.test...F1..130..test", "best.test...F1..131..test", "Best..test..129..test",
"best..test..130..test", "best..test..131..test"), class = "data.frame", row.names = c(NA,
-10L))

Basically, I want to extract all those columns that their name starts with

best..F1
best..F2
.
.

is there a way to do it without going to the data one by one and find its place ?


问:
NPE when injecting a static @Bean with AndroidAnnotations
I am trying to inject a static field using the @Bean from AndroidAnnotations:

```<code>@EBean
public class LogUtil {

    @Bean(CrashReporting.class) static Reporting reporting;

    public static void log(Activity activity, String method) {
        reporting.log(activity.getClass().getName() + ":" + method);
    }

}
</code>```

..

```<code>@EBean(scope = EBean.Scope.Singleton)
public class CrashReporting implements Reporting {

    @Override
    public void log(String text) {
        Log.d(getClass().getName(), text);
    }

}
</code>```

The reporting field is null at runtime:

```<code>Caused by: java.lang.NullPointerException:
Attempt to invoke interface method
'void com.example.staticinjection.Reporting.log(java.lang.String)'
on a null object reference
    at com.example.staticinjection.LogUtil.log(LogUtil.java:15)
    at com.example.staticinjection.MainActivity.onCreate(MainActivity.java:12)
    at android.app.Activity.performCreate(Activity.java:6237)
    ...
</code>```

Demo project

I created this demo project for you to reproduce the error.

答:
The injected fields are only available after an @AfterInject annotated method is called. Are you accessing the field after that point?

EDIT: you cannot really use static injection. You have to inject the bean to an instance member of the Activity:

```<code>@EActivity
public class MainActivity extends AppCompatActivity {

    @Bean
    LogUtil logger;

    @AfterInject
    public void afterInject() {
        logger.log(this, "AFTERINJECT");
    }
}

@EBean
public class LogUtil {

    @Bean(CrashReporting.class) Reporting reporting;

    public void log(Activity activity, String method) {
        reporting.log(activity.getClass().getName() + ":" + method);
    }

}
</code>```

Body:
I am trying to inject a static field using the @Bean from AndroidAnnotations:

@EBean
public class LogUtil {

    @Bean(CrashReporting.class) static Reporting reporting;

    public static void log(Activity activity, String method) {
        reporting.log(activity.getClass().getName() + ":" + method);
    }

}

..

@EBean(scope = EBean.Scope.Singleton)
public class CrashReporting implements Reporting {

    @Override
    public void log(String text) {
        Log.d(getClass().getName(), text);
    }

}

The reporting field is null at runtime:

Caused by: java.lang.NullPointerException:
Attempt to invoke interface method
'void com.example.staticinjection.Reporting.log(java.lang.String)'
on a null object reference
    at com.example.staticinjection.LogUtil.log(LogUtil.java:15)
    at com.example.staticinjection.MainActivity.onCreate(MainActivity.java:12)
    at android.app.Activity.performCreate(Activity.java:6237)
    ...

Demo project

I created this demo project for you to reproduce the error.

Body:
The injected fields are only available after an @AfterInject annotated method is called. Are you accessing the field after that point?

EDIT: you cannot really use static injection. You have to inject the bean to an instance member of the Activity:

@EActivity
public class MainActivity extends AppCompatActivity {

    @Bean
    LogUtil logger;

    @AfterInject
    public void afterInject() {
        logger.log(this, "AFTERINJECT");
    }
}

@EBean
public class LogUtil {

    @Bean(CrashReporting.class) Reporting reporting;

    public void log(Activity activity, String method) {
        reporting.log(activity.getClass().getName() + ":" + method);
    }

}


问:
Getting access to class declared in a file applied with 'apply from' in gradle
Hi I want to create a class in a separate file from my main build.gradle, when I run gradle I get ... Build file: build.gradle line: 2 ... > Could not get Property 'Foo' for root project ...

My files:

```<code>// build.gradle
apply from: 'foo.gradle'
println Foo // <- Line 2

// foo.gradle
class Foo {
}
</code>```

答:
Have a look at the documentation:

You can include the task class directly in the build script. This has the benefit that the task class is automatically compiled and included in the classpath of the build script without you having to do anything. However, the task class is not visible outside the build script, and so you cannot reuse the task class outside the build script it is defined in.

Source

You have 2 options to work around that

like you've found out you can use ext.Foo = Foo inside the foo.gradle

use the buildSrc feature from gradle have a look at this for more information

Body:
Hi I want to create a class in a separate file from my main build.gradle, when I run gradle I get ... Build file: build.gradle line: 2 ... > Could not get Property 'Foo' for root project ...

My files:

// build.gradle
apply from: 'foo.gradle'
println Foo // <- Line 2

// foo.gradle
class Foo {
}